Difference between revisions of "Nagios"

From Teknologisk videncenter
Jump to: navigation, search
m
Line 1: Line 1:
[[Category:Network Management]][[category:linux]][[category:FreeBSD]]
+
= check sensor example program =
[http://www.nagios.org Nagios Homepage]
+
== Script ==
 +
Configured on FreeBSD file /usr/local/libexec/nagios/check_humidity
 +
<source lang="perl">
 +
#!/usr/bin/perl
 +
if (scalar(@ARGV) != 2) {
 +
        print "Usage: $0 humidity_minimum humidity_maximum\n";
 +
        exit 3;
 +
}
 +
my $hum_min = shift;
 +
my $hum_max = shift;
  
<pdf>http://nagios.sourceforge.net/docs/nagios-3.pdf</pdf>
+
open(TEMP, "/usr/bin/temp |");
 +
while(my $line = <TEMP>) {
 +
        if ($line =~ m/Humidity.+?(\d+)/ ) {
 +
                my $humidity = $1;
 +
                if ($humidity < $hum_min) {
 +
                  print "Humidity is low under $hum_min% and now $humidity%\n";
 +
                  exit 1;
 +
                }
 +
                if ($humidity > $hum_max) {
 +
                  print "Humidity is high over $hum_max% and now $humidity%\n";
 +
                  exit 2;
 +
                }
 +
                print "Humidity is OK. Now at $humidity%\n";
 +
                exit 0;
 +
        }
 +
}
 +
</source>
  
 
+
= Links =
Henrik Thomsen
+
*[http://www.nagios.org Nagios Homepage]
 +
*[http://nagios.sourceforge.net/docs/nagios-3.pdf Nagios user manual]
 +
[[Category:Network Management]][[category:linux]][[category:FreeBSD]]

Revision as of 19:54, 14 May 2009

check sensor example program

Script

Configured on FreeBSD file /usr/local/libexec/nagios/check_humidity

#!/usr/bin/perl
if (scalar(@ARGV) != 2) {
        print "Usage: $0 humidity_minimum humidity_maximum\n";
        exit 3;
}
my $hum_min = shift;
my $hum_max = shift;

open(TEMP, "/usr/bin/temp |");
while(my $line = <TEMP>) {
        if ($line =~ m/Humidity.+?(\d+)/ ) {
                my $humidity = $1;
                if ($humidity < $hum_min) {
                  print "Humidity is low under $hum_min% and now $humidity%\n";
                  exit 1;
                }
                if ($humidity > $hum_max) {
                  print "Humidity is high over $hum_max% and now $humidity%\n";
                  exit 2;
                }
                print "Humidity is OK. Now at $humidity%\n";
                exit 0;
        }
}

Links