check_roomtemp.pl
changeset 1 56583be399db
parent 0 4a92d15de9dd
equal deleted inserted replaced
0:4a92d15de9dd 1:56583be399db
    68     return $temp;
    68     return $temp;
    69 }
    69 }
    70 
    70 
    71 sub report($$$) {
    71 sub report($$$) {
    72     my ( $temp, $warning, $critical ) = @_;
    72     my ( $temp, $warning, $critical ) = @_;
    73     $warning  = sprintf( "%.2f", $$warning );
    73     $$warning  = sprintf( "%.2f", $$warning );
    74     $critical = sprintf( "%.2f", $$critical );
    74     $$critical = sprintf( "%.2f", $$critical );
    75 
    75 
    76     $$temp =~ /^(\d+)\.(\d+)/;
    76     if ( $$temp >= $$critical ) {
    77     my $ta = $1;
       
    78     my $tb = $2;
       
    79 
       
    80     $warning =~ /^(\d+)\.(\d+)/;
       
    81     my $wa = $1;
       
    82     my $wb = $2;
       
    83 
       
    84     $critical =~ /^(\d+)\.(\d+)/;
       
    85     my $ca = $1;
       
    86     my $cb = $2;
       
    87 
       
    88     if ( $ta > $ca ) {
       
    89         print
    77         print
    90           "$NAME CRITICAL: +$$temp C | roomtemp=$$temp;$warning;$critical\n";
    78           "$NAME CRITICAL: +$$temp C | roomtemp=$$temp;$$warning;$$critical\n";
    91         exit $ERRORS{CRITICAL};
    79         exit $ERRORS{CRITICAL};
    92     }
    80     }
    93     if ( ( $ta == $ca ) && ( $tb >= $cb ) ) {
    81     if ( $$temp >= $$warning ) {
    94         print
    82         print
    95           "$NAME CRITICAL: +$$temp C | roomtemp=$$temp;$warning;$critical\n";
    83           "$NAME WARNING: +$$temp C | roomtemp=$$temp;$$warning;$$critical\n";
    96         exit $ERRORS{CRITICAL};
       
    97     }
       
    98     if ( $ta > $wa ) {
       
    99         print "$NAME WARNING: +$$temp C | roomtemp=$$temp;$warning;$critical\n";
       
   100         exit $ERRORS{WARNING};
    84         exit $ERRORS{WARNING};
   101     }
    85     }
   102     if ( ( $ta == $wa ) && ( $tb >= $wb ) ) {
    86     print "$NAME OK: +$$temp C | roomtemp=$$temp;$$warning;$$critical\n";
   103         print "$NAME WARNING: +$$temp C | roomtemp=$$temp;$warning;$critical\n";
       
   104         exit $ERRORS{WARNING};
       
   105     }
       
   106     print "$NAME OK: +$$temp C | roomtemp=$$temp;$warning;$critical\n";
       
   107     exit $ERRORS{OK};
    87     exit $ERRORS{OK};
   108 }
    88 }
   109 
    89 
   110 sub version($$) {
    90 sub version($$) {
   111     my ( $progname, $version ) = @_;
    91     my ( $progname, $version ) = @_;