--- projects/cms/source/host/generic/statgrab.pl 2001/02/05 17:13:26 1.26 +++ projects/cms/source/host/generic/statgrab.pl 2001/02/05 17:43:45 1.28 @@ -2,8 +2,8 @@ #----------------------------------------------------------------- # Machine statistics grabber -# $Author: pjm2 $ -# $Id: statgrab.pl,v 1.26 2001/02/05 17:13:26 pjm2 Exp $ +# $Author: tdb $ +# $Id: statgrab.pl,v 1.28 2001/02/05 17:43:45 tdb Exp $ # # A Perl script to return various information about a host machine # by examining the output of some common Unix/Linux commands. @@ -50,7 +50,7 @@ exit(0); # the host should check this when reading data # means the host must be checked and updated to work with newer versions. sub print_ident() { - print 'version statgrab.pl $Revision: 1.26 $'; + print 'version statgrab.pl $Revision: 1.28 $'; print "\n"; } @@ -185,35 +185,76 @@ sub include_osver() { } -# sub to get system uptime. +# sub to get system uptime in seconds. sub include_uptime() { + # debug stuff, all the different cases + + # normal + #my($uptime) = " 4:48pm up 49 day(s), 6:30, 201 users, load average: 0.33, 0.35, 0.38\n"; + # 0 days + #my($uptime) = " 4:48pm up 6:30, 201 users, load average: 0.33, 0.35, 0.38\n"; + # 0 hours + #my($uptime) = " 4:48pm up 49 day(s), 30 min(s), 201 users, load average: 0.33, 0.35, 0.38\n"; + # 0 mins + #my($uptime) = " 4:48pm up 49 day(s), 6 hr(s), 201 users, load average: 0.33, 0.35, 0.38\n"; + # 0 days and 0 mins + #my($uptime) = " 4:48pm up 6 hr(s), 201 users, load average: 0.33, 0.35, 0.38\n"; + # 0 days and 0 hours + #my($uptime) = " 4:48pm up 30 min(s), 201 users, load average: 0.33, 0.35, 0.38\n"; + # 0 hours and 0 mins + #my($uptime) = " 4:48pm up 49 day(s), 201 users, load average: 0.33, 0.35, 0.38\n"; + # grab the uptime my($uptime) = `$uptimebin`; # work out the days, hours, and minutes - if ($uptime =~ /hr/) { - # 0 minutes - $uptime =~ s/up ([0-9]+) .*, ([0-9]+) .*,/$1:$2:0/; - } - elsif ($uptime =~ /min/) { - # 0 hours - $uptime =~ s/up ([0-9]+) .*, ([0-9]+) .*,/$1:0:$2/; - } - elsif ($uptime =~ /day/) { + + if ($uptime =~ /day.*,\s+([0-9]+):([0-9]+)/) { # normal - $uptime =~ s/up ([0-9]+) .*, ([0-9]+):([0-9]+)/$1:$2:$3/; + $uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+):([0-9]+)/; + $uptime = "$1:$2:$3"; } else { - # 0 days - $uptime =~ s/up ([0-9]+):([0-9]+)/0:$1:$2/; + if ($uptime =~ /day/) { + if ($uptime =~ /hr/) { + # 0 minutes + $uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/; + $uptime = "$1:$2:0"; + } + elsif ($uptime =~ /min/) { + # 0 hours + $uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/; + $uptime = "$1:0:$2"; + } + else { + # 0 hours and 0 mins + $uptime =~ /up\s+([0-9]+)/; + $uptime = "$1:0:0"; + } + } + elsif ($uptime =~ /hr/) { + # 0 days and 0 minutes + $uptime =~ /up\s+([0-9]+)\s+/; + $uptime = "0:$1:0"; + } + elsif ($uptime =~ /min/) { + # 0 days and 0 hours + $uptime =~ /up\s+([0-9]+)\s+/; + $uptime = "0:0:$1"; + } + else { + # 0 days + $uptime =~ /up\s+([0-9]+):([0-9]+)/; + $uptime = "0:$1:$2"; + } } - # turn into minutes - + # turn into seconds $uptime =~ /([0-9]+):([0-9]+):([0-9]+)/; - $uptime = $3 + ($2 + $1*24)*60; - + $uptime = ($3+($2+($1*24))*60)*60; + + # print the value out &print_pair("unknown", "packet.os.uptime", $uptime); }