| | Stumble It! | Add to Mixx! | | diigo it | | Slashdot |

Wednesday, June 23, 2010

snmpset To the Rescue!

A big, ugly, hairy, monotonous task recently fell in my lap at work. I had to update a couple configuration settings in approximately 900 menu-driven network devices. Each device had an independent authentication method with four or five possible username/password combos, and different menu options depending on firmware version. Completing one box would take about 2-3 minutes. Multiply that by 900 and you're looking at a solid week of nothing but menu navigation and data entry.

This ranked very high on my "List-of-things-that-make-me-want-to-stab-my-eyes-out".

The disparity of versions and lack of a single configuration standard rendered my usual methods of scripting useless. A dark little rain cloud settled over my cube.

Then my boss made the comment, "These things have SNMP, right?"

I heard, "These things have SNMP write?"

I immediately started researching and sure enough, I could use the "snmpset" command to script the updates for me!

WIN!

Here is a copy of the 'bulk_snmpset.sh' script that I used to do the updates:
#!/bin/bash

while read HOST RWSTR; do
snmpset -v 2c -c $RWSTR $HOST <snmp_oid_here> a "192.168.100.100"
done < $1
I fed this script a flat text file (hosts_to_update.txt) with the 900 host names and their respective SNMP read/write string that looked like this:
10.10.10.1 SNMPrwSTRING1
10.10.10.2 SNMPrwSTRING2
10.10.10.3 snmpRWstring3
...
Actually making it worked, looked like this:
me@ubuntu:~/scripts $./bulk_snmpset.sh hosts_to_update.txt
All that remained was to capture the ones that failed and either adjust the script accordingly or take care of them manually

Monday, June 14, 2010

Clever Solution to IE Caching Ajax

I ran into a problem today where IE was caching my AJAX responses so updates wouldn't be displayed and after a bit of hand-wringing over some of the suggested solutions (swapping GETs for POSTs, re-writing the page inPHP, etc), I found a clever little solution - add a time stamp to the GET string.
var t = new Date().getTime();
...
ajaxUrl += '&timestamp='+t;
...
Adding this time stamp will differentiate the URL and thereby force IE to reload the Ajax content.

Win.

Tuesday, June 8, 2010

EeePC 701 Conky & World Daylight Wallpaper

UPDATE!!! 17 NOV 2010 - Recently, a change on the static.die.net site wget not downloading the actual world map, but just a black picture instead. It turns out that this only affected wget so to work around this, I've added the option of '-U "pwnd"' to the wget line to send a user-agent string and now it works again!

I read an article on Lifehacker yesterday about how you can set a day/night rotating map as your desktop background. At first I was like, "Hey, this is awesome!" Then I remembered my conky setup and realized that it wouldn't work as it requires a static color background behind the text in order to be visible and the world map is being constantly downloaded and over-writing the image so I was all, "Dangit, that would have been cool =(". Then I got an idea! I could use ImageMagick to glue the static conky background on to the world map so I high-fived myself and went, "pwnd!"

</valley_girl>

Here's what you'll get when you're done:
As the day progresses (and provided that you're connected to the internet), the day/night image will be updated every hour. Additionally, this script will draw a transparent gray band on the newly downloaded world map that you can overlay with your .conkyrc config.

Here's my setup:

.conkyrc
# This is my conky config, you'll need the
# Envy Code R VS font if you want to match my setup
# otherwise any monospaced font will do
alignment top_middle
border_width 0
default_color AAAAAA #white
draw_outline no
draw_shades no
use_xft yes
gap_x 0
gap_y 250
own_window yes
own_window_title conky
own_window_transparent yes
own_window_hints undecorated, sticky, below, skip_pager, skip_taskbar
double_buffer yes
update_interval 1.0
use_spacer none
short_units yes
draw_graph_borders no
default_outline_color black
use_spacer left
default_bar_size 250 5

TEXT
${font Envy Code R VS:size=40}${alignc}${time %R}${font Envy Code R VS:size=10}
${alignc}${time %A, %B %e}${font Envy Code R VS:size=8}
${voffset -50}${fs_bar 5, 250 /} sda${alignr}bat ${battery_bar}
${cpubar 5, 250} cpu${alignr}wlan ${wireless_link_bar 5, 250 wlan0}
${membar 5, 250} ram${alignr}${wireless_essid wlan0} ${addr wlan0} - ${upspeed wlan0} / ${downspeed wlan0}
${tab 775,0}${color black}.
animated_background.sh
#!/bin/bash
# This will download the day/night map and apply the gray band to the top of it
# You'll need to 'sudo apt-get install imagemagick' and
# 'chmod +x ./animated_background.sh' for this script to work
wget -r -U "pwnd" -O 800.jpg http://static.die.net/earth/mercator/800.jpg
convert -size 800x70 xc:'#40404090' ./grey_stripe.png
convert -resize 800x480! ./800.jpg ./800.jpg
composite -geometry -0+255 ./grey_stripe.png 800.jpg ~/Pictures/world.png
rm ./grey_stripe.png ./800.jpg
Then you'll need to set the script to run hourly using either crontab or gnome-schedule as shown in the Lifehacker link.

Cheers!