@peteashton and @BhamPostJoanna wondered " Is it possible to get a feed for twitters from a specific city?".
@aeioux pointed out http://twittermap.com
Twittermap, while it relies on twitterers twittering their location, gives results according to where twitterers are / were recently.
This yahoo pipe instead searches a twitterers' friends (any twitterer whose friends you can view) for the location in their profile. So the result is not 'live', but reflects where the friends are based.
Here's a first hack using yahoo pipes. The page parameter is for when there's more than 100 friends to deal with.
Friday, 21 March 2008
Brummie Twits
Sunday, 16 March 2008
IT Support in a large environment.
I wanted to jot down a few guiding principles, that have worked (I think) well for me. They work in the environment I'm in (Large FE college), very few 'special' users.
- Provide simple services. The question's not "what'll it do?", but "how well can I support it?". If it can do everything brilliantly, but it's broken often enough that it's not used, you lost. There are exceptions. Keep them limited.
- Monitor everything that matters up the wazoo. Don't wait for your users to tell you it's broke. They won't. They'd rather carve it on a siberian rock than tell you about it. And by the time someone does overcome their disdain for you and let you know there's a problem, it's been going on for ages, and you lost. There are exceptions. They are your friends.
- Recognise, and hammer into your colleagues when they forget, that your users, by and large, don't care about computers. They're not interested. They use the computer 'cos they've been told to. For work at least. And all they want to do is their job. And this is as it should be. When you wash your face, should you care about the details of water supply? No. All you want is water that's not brown. If you expect users to be interested in anything outside their job, you lost.
- Automate everything that's feasible. Once a script is right, it's right, and it will be tomorrow. If you're relying on users or tech support people to do task J the same today as they did yesterday, you lost.
- Document your recovery procedures. The last time you want to be trying to think is when it's all gone to hell and the phone's on fire. That's when you want to be following instructions blindly. If you're having to think what to do under pressure, you lost. I lose pretty often here. But it's worth trying.
Using nagios to monitor print configuration
Now this isn't a copy a previous post, which was about monitoring print queues. This is about monitoring our quite complex printing configuration system.
Again, a bit of background. We keep as much configuration info as we can in an LDAP directory. And we install printers on our windows desktops ( about 1,200 spread over several sites ) during either the startup scripts (for locally attached printer) or the login script (for network printers). We use the concept of a 'nearest printer', assigned to the workstation dependent on physical location.
So, sticking to network printers, we have:
- A CUPS queue per printer, served by Samba to windows desktops.
- A 'nearest printer' attribute in LDAP, attached to the workstation entry. This 'points to'..
- A printer entry per printer, with an 'installcommand' attribute, which gives an appropriate command line to install that printer on a workstation. This gets run during the login script.
- Look up my (the workstation's) LDAP entry.
- From my LDAP entry, get the nearest printers.
- For each nearestprinter, get the installcommand from the printer's LDAP entry.
- And run it.
But there's no referential integrity going on here. We can have orphans anywhere. A CUPS queue with no install commands. An installcommand referring to a non-existent CUPS queue. A workstation with a nearestprinter that doesn't exist. etc. Basically, config rot, caused by human failure to attend to detail.
And here we get to the point of it all. We have a nagios check called 'check_print_config', which checks all this, and creates a warning state if something's out of whack. It's posted below. As with most code posted here, it's finished to the point where it works. It's not great code. It does, I'd posit, do something interesting.
#!/usr/bin/perl -w
use strict;
my @nagiosCupsQueues;
my @nearestPrinterQueues;
my @installCommandQueues;
my @output = ();
# print "Getting monitored queues from nagios...\n";
@nagiosCupsQueues = (`grep check_cups_queue /etc/nagios2/conf.d/allPrintQueues.cfg | cut -f2 -d'!'`);
chop @nagiosCupsQueues;
# print "Getting installCommand queues from LDAP...\n";
@installCommandQueues = (`ldapsearch -LLL -x -b "ou=hosts,dc=example,dc=com" '(installcommand=*con2prt*)' installcommand | grep '/cd ' | grep -iv idcard | grep -iv tmu220 | grep -iv null | sort | uniq | cut -f4 -d" " | cut -f4
-d"\\\\"`);
chop @installCommandQueues;
# print "Getting nearestprinter queues from LDAP...\n";
@nearestPrinterQueues = (`ldapsearch -LLL -x -b "ou=hosts,dc=example,dc=com" '(&(objectclass=computer)(nearestprinter=*))' nearestprinter | grep nearestprinter | grep -iv lpt | grep -iv archicad | grep -iv tmu220 | grep -iv idcard | grep -iv null | sort | uniq | cut -f1 -d"," | cut -f2 -d"="`);
chop @nearestPrinterQueues;
foreach my $icq ( @installCommandQueues ) {
next if $icq =~ /^$/;
push(@output, "ICQ: $icq ") if ! grep(/^$icq$/i, @nagiosCupsQueues);
}
foreach my $npq ( @nearestPrinterQueues ) {
next if $npq =~ /^$/;
my $npqNotInCups = 0;
my $npqNoInstallCommand = 0;
$npqNotInCups = 1 if ! grep(/^$npq$/i, @nagiosCupsQueues);
$npqNoInstallCommand = 1 if ! grep(/^$npq$/i, @installCommandQueues);
# push(@output, "NPQ:$npq:") if ( $npqNoInstallCommand && $npqNotInCups );
my @duffClients = `ldapsearch -LLL -x -b "ou=hosts,dc=example,dc=com" "nearestprinter=cn=$npq,ou=hosts,dc=example,dc=com" dn | grep dn: | cut -f1 -d"," | cut -f2 -d"="`;
chop @duffClients;
push(@output, "NPQ:$npq: " . join(",", @duffClients) . " ") if ( $npqNoInstallCommand && $npqNotInCups );
}
#print Dumper([ \@output, ]);
if ( @output > 0 ) {
print "WARNING: " . join(" ",@output) . "\n";
exit 1;
} else {
print "OK\n";
exit 0;
}
Friday, 14 March 2008
Automating nagios configurations.
At the last count, we run something like 140 print queues, and as offices move, and printers get replaced, and 'stuff changes', queues are created and deleted and renamed. This post is about how I've addressed ensuring that nagios is monitoring all our queues, and minimising the opportunity for operator error.
A little background. We use CUPS to queue print jobs, and our technicians are free to create and delete queues as need be. They do not have access to the nagios configs.
So, the basic idea is that we periodically run a script on the nagios server that:
- Queries each of our print servers for a list of existing queues
- Creates a nagios config file for all print queues in the list
- signals nagios to restart, and re-read it's configuration
So we get a monitoring configuration that doesn't miss print queues out, nor alarms about print queues that no longer exist. And no-one has to remember.
Which is nice.
So, ( and I apologise in advance for the code. I'm a sysadmin. Whaddya expect. ). The following is a perl script called from cron, once for each CUPS server. We pass the server address, and a human-readable site name, and we get nagios code out on stdout, which is piped into the appropriate nagios config directory. It depends on lpstat, which queries the CUPS server.
#!/usr/bin/perl
$cupsServer = $ARGV[0];
$site = $ARGV[1];
@queues = `lpstat -h $cupsServer -p | grep printer | grep -iv "sent" | grep -iv "off-line" | grep -iv "unable" | grep -iv "attempt" | cut -f2 -d" "`;
chop @queues;
foreach $queue ( @queues ) {
print "define service{\n";
print "\tuse generic-service\n";
print "\thost_name $cupsServer\n";
print "\tservice_description CUPS_" . $queue . "\n";
print "\tservicegroups " . $site . "PrintQueues\n";
print "\tcontact_groups " . $site . "-printer-admins\n";
print "\tcheck_command check_cups_queue!" . $queue . "\n";
print "\tregister 1\n}\n\n";
print "define serviceextinfo{\n";
print " host_name " . $cupsServer . "\n";
print " service_description CUPS_" . $queue . "\n";
print " notes_url http://wiki.example.com/wiki/index.php?title=Nagios/" . $queue . "&action=edit&preload=Nagios/NewServiceTemplate\n";
print " action_url http://" . $cupsServer . ".example.com:631/printers/" . $queue . "\n";
print " icon_image HPlj4550p.gif\n}\n\n";
}
Coupla notes - the nagios action_url shows a clickable icon taking the user to the CUPS queue in question. The notes_url points to a wiki page. We use this to keep notes about the service.
This is all very well, but nagios won't pick up the changes without a restart. So once cron has built the config file, it does this:
export now=$( /bin/date "+\%s" ); #get the current time into a format nagios understands
export commandfile='/var/lib/nagios2/rw/nagios.cmd'; #identify the file nagios reads for external commands
/usr/bin/printf "[\%lu] RESTART_PROGRAM\n" $(( now + 30 )) > $commandfile #tell nagios to restart in 30 seconds
And Bob's yer uncle. Monitoring our CUPS queues with nagios means we become aware of problems quicker, and respond quicker. And automating the config makes this practical.