#!/usr/bin/php setDefaultHeader( array ( 'User-Agent' => 'Nagios Spider' ) ); $client->get ( 'https://www.hetzner.de/robot/' ); $client->post ( 'https://www.hetzner.de/robot/passwd.php', array ( 'login' => $user, 'passwd' => $pw ) ); $client->get ( 'https://www.hetzner.de/robot/traffic_1.php?art=monat' ); $buf = $client->currentResponse(); if ( !preg_match ( '@.*?.*?.*?.*?@s', $buf['body'], $match ) ) { echo $buf['body']; echo "Regex 1 failed!"; exit ( 3 ); } $postdata = array ( 'art' => 'monat', 'id' => $match['id'], 'id2' => $match['id2'], 'monat' => date ( 'n' ), 'jahr' => date ( 'Y' ), 'tag1' => 1, 'tag2' => 31, 'ip_anz' => $match['ip_anz'], 'sub_anz' => $match['sub_anz'], 'subip_anz' => $match['subip_anz'], 'ip0' => $ip, 'sub0' => $sub ); $client->post ( 'https://www.hetzner.de/robot/traffic_2.php', $postdata ); $buf = $client->currentResponse(); if ( !preg_match_all ( '@ (?P\d+\.\d+\.\d+\.\d+)[^<]*(?P[\.\d,]+)(?P[\.\d,]+)(?P[\.\d,]+)@', $buf['body'], $all_ips, PREG_SET_ORDER ) ) { echo $buf['body']; echo "Regex 2 failed!"; exit ( 3 ); } if ( !preg_match ( '@Gesamt:(?P[\.\d,]+)(?P[\.\d,]+)(?P[\.\d,]+)@', $buf['body'], $total ) ) { echo $buf['body']; echo "Regex 3 failed!"; exit ( 3 ); } function dataclean ( $str ) { return (int) str_replace( ',', '', str_replace( '.', '', $str ) ); } $str = ' - In = '.$total['in'].' GB, Out = '.$total['out'].' GB, Sum = '.$total['sum'].' GB | total_sum='.dataclean($total['sum']).', total_in='.dataclean($total['in']).', total_out='.dataclean($total['out']); foreach ( $all_ips as $row ) { $thisIpStr = str_replace ( '.', '-', $row['ip'] ); $str .= ', '.$thisIpStr.'_sum='.dataclean($row['sum']); $str .= ', '.$thisIpStr.'_in='.dataclean($row['in']); $str .= ', '.$thisIpStr.'_out='.dataclean($row['out']); } if ( dataclean($total['sum']) > $critical ) { echo "CRITCAL".$str; exit ( 2 ); } else if ( dataclean($total['sum']) > $warn ) { echo "WARN".$str; exit ( 1 ); } else { echo "OK".$str; exit ( 0 ); } ?>