Difference between revisions of "Nagios"
From Teknologisk videncenter
m (→Links) |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | + | = check sensor example program = | |
− | + | == Script == | |
+ | FreeBSD file /usr/local/libexec/nagios/check_humidity | ||
+ | <source lang="perl"> | ||
+ | #!/usr/bin/perl | ||
+ | # THIS IS A TEST DUMMY SERVICE | ||
+ | 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; | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | == configuration == | ||
+ | <source lang="text"> | ||
+ | ######################################################## | ||
+ | # Folgende er tilfojet til filen | ||
+ | # /usr/local/etc/nagios/commands.cfg | ||
+ | # OBS: Paa nogle systemer hedder filen | ||
+ | # /usr/local/nagios/etc/commands.cfg | ||
+ | define command{ | ||
+ | command_name check_humidity | ||
+ | command_line $USER1$/check_humidity $ARG1 | ||
+ | } | ||
+ | ######################################################## | ||
+ | #Flg. er tilfojet til filen | ||
+ | # /usr/local/etc/nagios/hosts.cfg som er en fil | ||
+ | # der beskriver en host. Filen vedlagt. | ||
+ | define service { | ||
+ | use router-ping | ||
+ | host_name localhost | ||
+ | service_description Humidity | ||
+ | check_command check_humidity!60 80 | ||
+ | } | ||
+ | </source> | ||
+ | <!-- | ||
+ | <source lang="text"> | ||
+ | define service { | ||
+ | name five ; The name of this service template | ||
+ | use generic-service ; Inherit default values from the generic-service definition | ||
+ | check_period 24x7 ; The service can be checked at any time of the day | ||
+ | max_check_attempts 4 ; Re-check the service up to 4 times in order to determine its final (hard) state | ||
+ | normal_check_interval 5 ; Check the service every 5 minutes under normal conditions | ||
+ | retry_check_interval 1 ; Re-check the service every minute until a hard state can be determined | ||
+ | contact_groups router-admins ; Notifications get sent out to everyone in the 'admins' group | ||
+ | notification_options w,u,c,r ; Send notifications about warning, unknown, critical, and recovery events | ||
+ | notification_interval 60 ; Re-notify about service problems every hour | ||
+ | notification_period 24x7 ; Notifications can be sent out at any time | ||
+ | register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE! | ||
+ | } | ||
− | + | define service { | |
+ | use five | ||
+ | host_name localhost | ||
+ | service_description Humidity | ||
+ | check_command check_humidity!60 80 | ||
+ | } | ||
+ | </source> | ||
+ | --> | ||
+ | |||
+ | = Links = | ||
+ | *[http://www.nagios.org Nagios Homepage] | ||
+ | *[http://nagios.sourceforge.net/docs/nagios-3.pdf Nagios user manual] | ||
+ | [[Category:Network Management]][[category:linux]][[category:FreeBSD]][[Category:Perl]] |
Latest revision as of 09:54, 5 November 2009
check sensor example program
Script
FreeBSD file /usr/local/libexec/nagios/check_humidity
#!/usr/bin/perl
# THIS IS A TEST DUMMY SERVICE
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;
}
}
configuration
########################################################
# Folgende er tilfojet til filen
# /usr/local/etc/nagios/commands.cfg
# OBS: Paa nogle systemer hedder filen
# /usr/local/nagios/etc/commands.cfg
define command{
command_name check_humidity
command_line $USER1$/check_humidity $ARG1
}
########################################################
#Flg. er tilfojet til filen
# /usr/local/etc/nagios/hosts.cfg som er en fil
# der beskriver en host. Filen vedlagt.
define service {
use router-ping
host_name localhost
service_description Humidity
check_command check_humidity!60 80
}