Difference between revisions of "Nagios check wheather"

From Teknologisk videncenter
Jump to: navigation, search
m (New page: == på CentOS == filen /usr/lib/nagios/plugins/check_weather indeholder. Husk at køre ''chmod +x på filen''. <source lang=perl> #!/usr/bin/perl use strict; use warnings; use Weather::Goo...)
 
m
Line 46: Line 46:
 
         service_description viborg-temp
 
         service_description viborg-temp
 
         check_command check_weather!viborg 10 20
 
         check_command check_weather!viborg 10 20
 +
</source lang=txt>
 +
= Genstart af nagios =
 +
<source lang=cli>
 +
[root@mars ~]# service nagios restart
 
</source>
 
</source>
 
[[Category:Perl]]
 
[[Category:Perl]]

Revision as of 14:19, 10 November 2009

på CentOS

filen /usr/lib/nagios/plugins/check_weather indeholder. Husk at køre chmod +x på filen.

#!/usr/bin/perl
use strict;
use warnings;
use Weather::Google;
if (scalar(@ARGV) != 3) {
        print "Usage: $0 town temp_minimum temp_maximum\n";
        exit 3;
}
my $town = shift;
my $minimum = shift;
my $maximum = shift;

my $gw = new Weather::Google($town);
my $temp = $gw->current('temp_c');
if ( ! defined($temp) ) {
        print "Fejl..";
        exit(3); # Error getting temperature
}
if ( $temp < $minimum ) {
    print "temperatur for lav $temp. Skal vaere mellem $minimum og $maximum";
        exit(1); # low
}
if ( $temp > $maximum ) {
    print "temperatur for hoj $temp. Skal vaere mellem $minimum og $maximum";
        exit(1); # high
}
    print "temperatur $temp. Skal vaere mellem $minimum og $maximum";
exit(0); #  OK within range

/etc/nagios/objects/commands.cfg

define command{
        command_name    check_weather
        command_line    $USER1$/check_weather $ARG1
}

/etc/nagios/objects/localhost.cfg

define service {
        use local-service
        host_name localhost
        service_description viborg-temp
        check_command check_weather!viborg 10 20
</source lang=txt>
= Genstart af nagios =
<source lang=cli>
[root@mars ~]# service nagios restart