Nagios check wheather

From Teknologisk videncenter
Jump to: navigation, search

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

Genstart af nagios

[root@mars ~]# service nagios restart