diff options
-rw-r--r-- | sitesummary-collector.cgi | 36 | ||||
-rwxr-xr-x | sitesummary-nodes | 110 |
2 files changed, 123 insertions, 23 deletions
diff --git a/sitesummary-collector.cgi b/sitesummary-collector.cgi index c79190d..70bca7c 100644 --- a/sitesummary-collector.cgi +++ b/sitesummary-collector.cgi @@ -95,10 +95,10 @@ sub extract_unique_id { my $eth2mac; open(IFCONFIG, "system/ifconfig-a") || die "Unable to read ifconfig-a"; while (<IFCONFIG>) { - chomp; - $eth0mac = $1 if (m/^eth0\s+Link encap:Ethernet HWaddr (\S+)/); - $eth1mac = $1 if (m/^eth1\s+Link encap:Ethernet HWaddr (\S+)/); - $eth2mac = $1 if (m/^eth2\s+Link encap:Ethernet HWaddr (\S+)/); + chomp; + $eth0mac = $1 if (m/^eth0\s+Link encap:Ethernet HWaddr (\S+)/); + $eth1mac = $1 if (m/^eth1\s+Link encap:Ethernet HWaddr (\S+)/); + $eth2mac = $1 if (m/^eth2\s+Link encap:Ethernet HWaddr (\S+)/); } close (IFCONFIG); #print STDERR "MAC: $eth0mac\n"; @@ -110,12 +110,12 @@ sub process_entry { my ($peeripaddr, $peername, $filename) = @_; my $dirname; if ($filename =~ m/(.+).tar.gz$/) { - $dirname = $1; - mkdir $dirname; - chdir $dirname; - `tar zxf $filename`; + $dirname = $1; + mkdir $dirname; + chdir $dirname; + `tar zxf $filename`; } else { - die "Unhandled file format '$filename'"; + die "Unhandled file format '$filename'"; } open(PEERINFO, ">peerinfo") || die; @@ -127,20 +127,20 @@ sub process_entry { my $status = "new"; if ( -d $newdir ) { - `rm -r $newdir`; - my $status = "update"; + `rm -r $newdir`; + my $status = "update"; } rename $dirname, $newdir || die; for my $handler (<$handlerdir/*>) { - `$handler $newdir $status`; + `$handler $newdir $status`; } } sub get_peerinfo { my $sockethandle = shift; - # Return something while this function do not work. + # XXX Return something while this function do not work. return ("127.0.0.1", "localhost"); # XXX The call to sockaddr_in trigger "Bad arg length for @@ -148,12 +148,12 @@ sub get_peerinfo { # /usr/lib/perl/5.8/Socket.pm line 198." No idea why. my ($peerport, $peeripaddr) = sockaddr_in(getpeername($sockethandle)); if ($peerport) { - my $peername = gethostbyaddr($peeripaddr, AF_INET); + my $peername = gethostbyaddr($peeripaddr, AF_INET); - if ("" eq $peername) { - syslog('warning', "client without DNS entry connected from \[$peeripaddr\]"); - $peername = "$peeripaddr"; - } + if ("" eq $peername) { + syslog('warning', "client without DNS entry connected from \[$peeripaddr\]"); + $peername = "$peeripaddr"; + } } else { # Running on the command line, use test host $peeripaddr = "127.0.0.1"; diff --git a/sitesummary-nodes b/sitesummary-nodes index 1ac8fa1..fd59d62 100755 --- a/sitesummary-nodes +++ b/sitesummary-nodes @@ -10,7 +10,7 @@ use SiteSummary; use Getopt::Std; my %opts; -getopts("m", \%opts); +getopts("mn", \%opts); my %hostnames; @@ -18,6 +18,8 @@ for_all_hosts(\&handle_host); if ($opts{'m'}) { print_munin_list(); +} elsif ($opts{'n'}) { # XXX Nagios config generation do not work yet + generate_nagios_config(); } else { print_list(); } @@ -34,13 +36,13 @@ sub print_list { } } -sub is_munin_client { - my $hostid = shift; - # Check debian/dpkg-l for 'ii *munin-node ' +sub is_pkg_installed { + my ($hostid, $pkgname) = @_; + # Check debian/dpkg-l for 'ii *pkgname ' my $path = get_filepath_current($hostid, "/debian/dpkg-l"); if (open (my $fh, $path)) { while(<$fh>) { - if (m/^ii *munin-node /) { + if (m/^ii *$pkgname /) { close($fh); return 1 } @@ -50,6 +52,17 @@ sub is_munin_client { return undef; } +sub is_munin_client { + my $hostid = shift; + return is_pkg_installed($hostid, "munin-node"); +} + +sub is_nagios_client { + my $hostid = shift; + return is_pkg_installed($hostid, "nagios-nrpe-server") || + is_pkg_installed($hostid, "nagios-text"); +} + sub print_munin_list { for my $hostname (sort keys %hostnames) { next unless (is_munin_client($hostnames{$hostname})); @@ -65,3 +78,90 @@ sub print_munin_list { EOF } } + +sub generate_nagios_config { + for my $hostname (sort keys %hostnames) { + my $hostid = $hostnames{$hostname}; + next unless (is_nagios_client($hostid)); + + my $ifconfigpath = get_filepath_current($hostid, "/system/ifconfig-a"); + my $peerinfopath = get_filepath_current($hostid, "/peerinfo"); + open (F, "<", $peerinfopath)||die "Unable to read from $peerinfopath"; + my ($address) = split(/\s+/, scalar <F>); + close(F); + + # first, check ping to see if the other checks should be performed + print <<EOF; +##################### $hostname ####################### +define host { + host_name $hostname + address $address +} +define service { + use server-service + host_name $hostname + service_description ping + check_command check_ping!100.0,20%!500.0,60% +} +EOF + + print <<EOF if is_pkg_installed($hostid, "openssh-server"); +define service { + use server-service + host_name $hostname + service_description ssh + check_command check_ssh +} +EOF + + my %tcpservices = + ( + 139 => { name => 'samba', package => 'samba' }, + 631 => { name => 'cups', package => 'cupsys' }, + 636 => { name => 'ldaps', package => 'slapd' }, + 3128 => { name => 'squid', package => 'squid' }, +# 10000 => { name => 'webmin', package => 'webmin' }, + ); + + for my $port (sort { $a <=> $b } keys %tcpservices) { + next if (exists $tcpservices{$port}->{package} && ! + is_pkg_installed($hostid, + $tcpservices{$port}->{package})); + my $servicename = $tcpservices{$port}->{name}; + print <<EOF; +define service { + use server-service + host_name $hostname + service_description $servicename + check_command check_tcp!$port +} +EOF + } + # check munin if munin-node is installed + # check hw and sw raid status + # check hardware status + # check free swap + # check X font server + # check LDAP + # check DNS + # check disk free space + my $path = get_filepath_current($hostid, "/system/procmounts"); + if ( -e $path ) { + open (F, "<", $path) || die "unable to read from $path"; + while (<F>) { + chomp; + my ($dev, $partition, $fs, $opts) = split; + my $warn = 10; + my $crit = 5; + print <<EOF; +define service { + use server-service + host_name $hostname + service_description Disk $partition + check_command check_disk!$warn%!$crit%!$partition +} +EOF + } + } + } +} |