diff --git a/tools/runtime/route-servers/nagios-check-last-updated.php b/tools/runtime/route-servers/nagios-check-last-updated.php index 766ab73ee..e8aca31d4 100644 --- a/tools/runtime/route-servers/nagios-check-last-updated.php +++ b/tools/runtime/route-servers/nagios-check-last-updated.php @@ -1,6 +1,6 @@ $threshold seconds ago $s = curl_init(); -curl_setopt( $s, CURLOPT_URL, $url . '/' . $threshold ); +curl_setopt( $s, CURLOPT_URL, $url ); curl_setopt( $s, CURLOPT_HTTPHEADER, [ 'X-IXP-Manager-API-Key: ' . $key ] ); -curl_setopt( $s, CURLOPT_HEADER, true ); +curl_setopt( $s, CURLOPT_RETURNTRANSFER, true ); $json = curl_exec($s); + if( !curl_getinfo($s,CURLINFO_HTTP_CODE) == 200 ) { echo "UNKNOWN: non-200 status code returned by API: " . curl_getinfo($s,CURLINFO_HTTP_CODE) . "\n"; exit( 3 ); } -if( !( $routers = json_decode( $json ) ) ) { +if( !( $routers = json_decode( $json, true ) ) ) { echo "UNKNOWN: could not decode JSON response from API\n"; exit( 3 ); } @@ -63,10 +64,11 @@ } else if( time()-$threshold > $r['last_updated_unix'] ) { $bad[] = $handle; } else { - $ok = $handle; + $ok[] = $handle; } } + $resp = ''; if( count( $bad ) ) { $resp .= 'ERROR: the following router(s) have not updated in more than ' . $threshold . 'secs: ' . implode( ', ', $bad ) . '. ';