#!/usr/bin/perl # # SysWatch v1.5.1 - CGI Script to gather and report various system information. # Copyright (C) 2000-2001 Chris Martino # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # All configuration is now done to the syswatch.cf file. $config = "./syswatch.cf"; require "$config"; ##### Do NOT edit below here unless you know what you're doing!! ##### # ------------------------------------------------------------------- # my $temp_command; my @devinfo; my @df_info; my $info; my @show_list; my $dev_count= 0; my $devline; my $bad_line= ""; my $sysos = `uname -sr`; my $uptime = `uptime`; my $tmptop = '/tmp/tmptop'; my $tmpw = '/tmp/tmpw'; my $tmptail = '/tmp/tmptail'; if ( $sysos =~ /freebsd/i ) { $memory = `expr \`cat /var/run/dmesg.boot | grep "real memory" | cut -f5 -d" "\` \/ 1048576`; $swap = `$toploc | grep -i swap | cut -f2 -d" " | cut -f1 -d"M"`; $sysname = `hostname`; } elsif ( $sysos =~ /netbsd/i ) { $memory = `expr \`sysctl -a | grep hw.physmem | cut -c13-\` \/ 1048576`; $swap = `expr \`swapctl -sk | sed 'y/k/ /' | awk '{ print \$2 }'\` \/ 1024`; $sysname = `hostname`; } elsif ($sysos =~ /OpenBSD/i) { $memory = `expr \`sysctl -a | grep hw.physmem | cut -c13-\` \/ 1048576`; $swap = `expr \`swapctl -sk | sed 'y/k/ /' | awk '{ print \$2 }'\` \/ 1024`; $sysname = `hostname -s`; } elsif ( $sysos =~ /linux/i ) { $memory = `free -m |grep -i mem | awk '{print \$2}'`; $swap = `free -m |grep -i swap | awk '{print \$2}'`; $sysname = `hostname -f`; } elsif ( $sysos =~ /sunos/i ) { $memgather = `$toploc | grep Mem`; if ( $memgather =~ /^Memory\: (\d+)M real.*(\d+)M swap in use, (\d+)M swap/ ) { $memory = $1; $swap = $2 + $3; } else { $memory = $memory; $swap = $swap; } $sysname = `hostname`; } else { $memory = $memory; $swap = $swap; }; $df_command= "df -k"; @devinfo = `$df_command`; foreach $devline ( @devinfo ) { chomp( $devline ); if( $bad_line ne "" ) { $df_info[0]= $bad_line; ($df_info[1], $df_info[2], $df_info[3], $df_info[4], $df_info[5] ) = split( ' ', $devline); $bad_line = ""; } else { @df_info = split( ' ', $devline); } if( $df_info[1] ne "" ) { $bad_line = ""; } else { # Okay we proably have a long line for the devices so df has wraped the line ARG. $bad_line= $df_info[0]; # save this for next pass }; if ((not (( $df_info[0] =~ /^Filesystem/ ) || ( in( $df_info[0], @exclude_devs ) ))) && ( $bad_line eq "")) { if( not(( $exclude_nfs eq "TRUE" ) && ( $df_info[0] =~ /^.*:.*$/ )) ) { $show_list[ $dev_count++]=[ @df_info ]; }; } } chomp($uptime,$sysos,$sysname,$memory,$swap); open(OUTF,">>$tmptop"); if ( $sysos =~ /hpux/i ) { print OUTF `ps aux |grep -A50 PID |grep -v grep`; } elsif ( $sysos =~ /linux/i ) { print OUTF `$toploc b n 1 |grep -A50 PID`; } else { print OUTF `$toploc -o cpu -d1 50`; }; close(OUTF); open(OUTF,">>$tmpw"); print OUTF `w`; close(OUTF); open(OUTF,">>$tmptail"); print OUTF " "; print OUTF `tail -$taillines $logs`; close(OUTF); print "Content-type: text/html\n\n"; print "\n"; print "\n"; print "SysWatch -> $sysname\n"; if ( $refresh == 1 ) { print "\n"; } print "\n"; print "\n"; print <

       System Information
SysInfo    : $sysname
    $uptime

OS	: $sysos
RAM	: $memory MB (approx.)
Swap	: $swap MB (approx.)

EndHTML ; if ( $showdrivemap == 1 ) { print "

\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; if ( $dev_count > 0 ) { foreach $item ( @show_list ) { $disk_full= 0; # Used to graph the amount of disk space full print "\n"; print "\n"; print "\n"; print "\n"; } else { print " @{$item}[4]\n"; }; } else { print " @{$item}[4]\n"; }; print "\n"; print "\n"; print "\n"; print "\n"; } } else { print "\n"; print "\n"; print "\n"; } print "
\n"; print "\n"; print "       Drive Information\n"; print "\n"; print "
FilesystemMountUseUsedAvailSize
@{$item}[0]@{$item}[5]\n"; $disk_full= @{$item}[4]; chop( $disk_full); if( $disk_full < 90 ) { if( $disk_full == 0 ) { print "@{$item}[4]" . comify(@{$item}[2]) . "K" . comify(@{$item}[3]) . "K" . comify(@{$item}[1]) . "K
No Disk info avaible

"; } if ( $showwhat == 1 ) { print "

\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "       Who, What, When\n"; print "\n"; print "
\n";
   open(INF, "$tmpw");
      @w = ;
   close(INF);
   print "\n@w";
   print "

"; } if ( $showhogs == 1 ) { print "

\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "       Resource Information\n"; print "\n"; print "
";
   open(INF, "$tmptop");
      @top = ;
   close(INF);
   print "@top";
   print "

"; } if ( $showtail == 1 ) { print "\n"; print "

\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "       System Messages\n"; print "\n"; print "
\n";
   open(INF, "$tmptail");
      @tail = ;
   close(INF);
   print "\n@tail";
   print "

"; } print "
Output produced by SysWatch 1.5.1\n"; print "\n"; system ("rm $tmptop"); system ("rm $tmpw"); system ("rm $tmptail"); sub in { $this= shift; @here=@_; $found_it=0; for( $num=0; (($num < scalar( @here)) && ( ! $found_it )); $num++) { if( $here[ $num] eq $this ) { $found_it=1; }; }; return $found_it; }; sub comify ($) { my $text = reverse $_[0]; $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g; return scalar reverse $text; }