#! /usr/bin/perl ### ### XMLSNMP.PL ### (c) 2003 Software Poetry, Inc. ### http://www.softwarepoetry.com/webob ### ### Cover for snmpget to return an xml fragment for use in webob. ### Edit the values in the configuration section for your purposes, ### It will currently interpret the first arg as an override for server, ### the second as an override for community, then any more args as ### overrides for the variable list. ### ### License: This software is provided as-is with NO WARRANTY WHATSOEVER. ### Software Poetry makes no claims as to its fitness for any purpose. ### This file and any derivatives or translations of it may be freely ### copied and redistributed so long as the original license and copyright ### notices are included and not altered. ### use strict; # +------------------------------------------------------------------------- # | Configuration Variables # +------------------------------------------------------------------------- my $c_szCommunityDefault = "public"; my $c_szServerDefault = "localhost"; my @c_rgVarsDefault = ( "enterprises.ucdavis.memory.memTotalSwap.0", "enterprises.ucdavis.memory.memAvailSwap.0", "enterprises.ucdavis.memory.memTotalReal.0", "enterprises.ucdavis.memory.memTotalFree.0", "enterprises.ucdavis.laTable.laEntry.laLoad.1" ); # +------------------------------------------------------------------------- # | Entrypoint # +------------------------------------------------------------------------- my $szServer = $c_szServerDefault; if ($#ARGV >= 0) { $szServer = $ARGV[0]; } my $szCommunity = $c_szCommunityDefault; if ($#ARGV >= 1) { $szCommunity = $ARGV[1]; } my $szCommand = "snmpget -Oq -v 1 -c $szCommunity $szServer "; if ($#ARGV >= 2) { foreach my $iarg (2 .. $#ARGV) { $szCommand .= "$ARGV[$iarg] "; } } else { for my $szVar (@c_rgVarsDefault) { $szCommand .= "$szVar "; } } if (!open(VARSTREAM, "$szCommand |")) { print "Failed executing command:\n$szCommand\n"; exit(1); } print "\n"; my $fSawSomeVars = 0; while () { $fSawSomeVars = 1; s/&/&/g ; s/\"/"/g ; s/\/>/g ; s/ /<\/name>\n\t\t/ ; chop; print "\t\n\t\t$_\n\t\n"; } print "\n"; if (!$fSawSomeVars) { exit(2); } exit(0);