Maybe this will be of interest to some of you.....if it is, please let us know on this forum.
Below is example code I have in a Raspberry Pi (RPI) that can connect to a node and make a PDF image of five screens of interest. The screens of interest for me are:
- The main node screen "Status"
- The Mesh Status
- A single run of the WiFi scan
- The basic Setup screen
- The Port Forwarding, DHCP, and Services screen
Right now we don't have any tunnels so I don't care about that.
The screens are automatically captured into temporary PDF files then finally assembled into a single 5-page PDF document with the name of the node as the filename. These PDF documents can be a real big help when rebuilding a node.
I'm not a programmer so this is probably considered real hacky. :)
Below is the example code:
==============
#!/bin/bash
wkhtmltopdf -s Letter http://nodename.local.mesh:8080/cgi-bin/status temp1.pdf
wkhtmltopdf -s Letter http://nodename.local.mesh:8080/cgi-bin/mesh temp2.pdf
wkhtmltopdf -s Letter http://nodename.local.mesh:8080/cgi-bin/scan temp3.pdf
wkhtmltopdf -s Letter --username 'root' --password 'pAsSw0rD' http://nodename.local.mesh:8080/cgi-bin/setup temp4.pdf
wkhtmltopdf -s Letter --username 'root' --password 'pAsSw0rD' http://nodename.local.mesh:8080/cgi-bin/ports temp5.pdf
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=nodename.pdf temp1.pdf temp2.pdf temp3.pdf temp4.pdf temp5.pdf
rm ./temp*.pdf
==============
For the above example, I would name the file 'get-nodename' and create additional files for other nodes. For nodes I have the root password for I would put the password in the script. If I don't have a password then those affected nodes will have page 4 and 5 blank except for "Authorization Required" printed at the top of the page.
Anyway, having PDFs like this can be a big help if a node has to be reconfigured.
The RPI needs to have the 'wkhtmltopdf" and 'gs' (GhostScript) installed. Also when wkhtmltopdf is run, there are some warnings and errors but all seems to work 100%. The errors look like this:
- libEGL warning: DRI2: failed to open swrast (search paths /usr/lib/arm-linux-gnueabihf/dri:${ORIGIN}/dri:/usr/lib/dri) Loading page (1/2)
- QXcbConnection: XCB error: 145 (Unknown), sequence: 164, resource id: 0, major code: 139 (Unknown), minor code: 20
Do I care? No as it all works!
I made another script that calls all the scripts for each node but first does a ping test and if that doesn't pass it skips the dead node and goes to the next node on the list.
73 - Mike ab4yy
This is a great approach to documenting nodes.Thanks for sharing it with the group.
I'm having problems authenticating with the node. I even tried uploading my public key to the node but it still doesn't authenticate.
Which version of wkhtmltopdf are you using? apt-get on Debian jessie got me ver 0.12.1. Do you know of any other gotcha's?
73, Mark, N2MH
I am running the same version of wkhtmltopdf as you (0.12.1).
I don't think installing a ssh key will do anything for this.
I'm not aware of any other gotchas except for those errors I mentioned earlier, it all works here and I have used it on several nodes I have access to.
73, Mike ab4yy
I ran this code on a different machine and it ran OK.
Be advised that in later AREDN code, the WiFi scan is password protected. Thus, you will need to modify the script to send credential information as done for other password protected pages.
I got a script like this working and was able to use it to construct a snapshot of our nodes before updating to 3.16.1.1. Very helpful!
I found Ghostscript (gs) a bit cranky so I decided to use "PDF Toolkit". It works nicely. The free version is works fine and there are windows and Linux versions.
Thanks to Mike for a great idea!
-Jonathan
Thanks for the feedback Mark and Jonathan.
Given the get-NODE1, get-NODE2, get-NODE3, etc. scripts for each node, the following script will run all the nodes if they are ping-able and will also make a singe ALL-NODES pdf. It also make an HTML page with hotlinks for all the PDFs. Again, it is all kludged together but works.
===== MASTER RUN SCRIPT - OR FOR CRON JOB ===============
#!/bin/bash
cd /home/pi/mesh/indiv-setups
if ping -c 2 NODE1 &> /dev/null
then
source ./get-NODE1
fi
if ping -c 2 NODE2 &> /dev/null
then
source ./get-NODE2
fi
.
.(etc.Repeat if/then/fi..for as many node scripts as you have)
.
.
.
pdfunite $(ls -v *.pdf) ALL-NODES.pdf
cp *.pdf /var/www/html/mesh-nodes/
rm /home/pi/mesh/indiv-setups/*.pdf
# Get the PDF filenames in a folder and
# create HTML link to them on webpage
rm /var/www/html/mesh-stats-pdfs.html
#list_dir=`ls -t /path/to/dir/`
list_dir=`ls /var/www/html/mesh-nodes/`
for i in $list_dir
do
echo "<a href=\"/mesh-nodes/$i\">$i</a>" >> /var/www/html/mesh-stats-pdfs.html
done
echo done!
==================
The result HTML page looks like this (hotlinks in the HTML):
ALL-NODES.pdf NODE1.pdf NODE2.pdf NODE3.pdf
That is okay but I really would prefer to have it in a column like:
ALL-NODES.pdf
NODE1.pdf
NODE2.pdf
NODE3.pdf
I could not get it to output like that and finally had to give up. If anyone knows of the solution, I would appreciate knowing about it. It's not a biggie, just would be nicer in a column. (Oh, the 'rm /var/www/html/mesh-stats-pdfs.html' probably should be done with an 'if exists' conditional. :) )
73, Mike ab4yy
> I could not get it to output like that and finally had to give up.
Add a backslash: \
at the end of each line you want to continue (but not the last one).
-Jonathan
Thanks again Jonathan. Somehow I missted your forum entry but I did figure it out myself and did it a bit differently:
I simply added the<br> tag.
- Mike
I overhauled my master run script to work better.
If anyone is interested here it is.
###################################################
cd /home/pi/mesh/indiv-setups
rm -f /home/pi/mesh/indiv-setups/*.pdf
#### execute all individual node script (the wkhtmltopdf scripts)
./get-node1
./get-node2
./get-node3
....etc
rm -f ./temp*.pdf
#### combine all into a dated PDF for archive
today=`date '+%Y_%m_%d__%H_%M_%S'`;
outputfilename="$today.pdf"
#echo $outputfilename
pdfunite $(ls -v *.pdf) $outputfilename
#### MOVE DATED PDF TO ARCHIVE
mv /var/www/html/mesh-nodes/*_*_*.pdf /var/www/html/mesh-nodes/archive/
####
cp -r *.pdf /var/www/html/mesh-nodes/
# Get the PDF filenames in a folder and
# create HTML link to them on homepage
rm -f /var/www/html/mesh-stats-pdfs.html
list_dir=`ls /var/www/html/mesh-nodes/`
for i in $list_dir
do
echo "<a href=\"/mesh-nodes/$i\">$i</a><br>" >> /var/www/html/mesh-stats-pdfs.html
done
###################################################
I run the scrip manually when I want to. I tried to get it to run as a cron but that never did work and I don't know why. But for me the script may be in its final state and works well.
73 - Mike ab4yy
Loving this discussion.
Thank you all.
...dan wl7coo
I change several of my node scripts to also get the CHARTS information in the PDF. That required some changes to the wkhtmltopdf options. Here is an example script:
## example get-node1 script
#############################################
#!/bin/bash
wkhtmltopdf -s Letter http://node1.local.mesh:8080/cgi-bin/status temp1.pdf
wkhtmltopdf -s Letter http://node1.local.mesh:8080/cgi-bin/mesh temp2.pdf
wkhtmltopdf -s Letter http://node1.local.mesh:8080/cgi-bin/scan temp3.pdf
wkhtmltopdf -s Letter --javascript-delay 8000 http://node1.local.mesh:8080/cgi-bin/signal temp4.pdf
wkhtmltopdf -s Letter --username 'root' --password 'abc123' http://node1.local.mesh:8080/cgi-bin/setup temp5.pdf
wkhtmltopdf -s Letter --username 'root' --password 'abc123' http://node1.local.mesh:8080/cgi-bin/ports temp6.pdf
pdfunite temp1.pdf temp2.pdf temp3.pdf temp4.pdf temp5.pdf temp6.pdf node1.pdf
rm -f ./temp*.pdf
#############################################
You can see how I put that delay of 8000. If the node is stubborn (takes longer), you can try changing it to 10000 as I had to do that with one node.
I also have a node now that is currently slow/weak path where I decided not to have the charts info extracted until the node lath can be improved.
There are also options like "--enable-javascript --no-stop-slow-scripts" that can be played with if needed.
I too found Ghostscript (gs) to sometime be problematic so now use pdfunite instead. The syntax is simpler too.
Does anyone know a simple way to have pfdunite combine all files in current directory without specifically listing them?
73 - Mike ab4yy