Skip to content

Commit

Permalink
Improve nagios check for router last updated
Browse files Browse the repository at this point in the history
  • Loading branch information
barryo committed May 24, 2024
1 parent a636a5f commit 8589d00
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tools/runtime/route-servers/nagios-check-last-updated.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

// Copyright (C) 2009 - 2019 Internet Neutral Exchange Association Company Limited By Guarantee.
// Copyright (C) 2009 - 2024 Internet Neutral Exchange Association Company Limited By Guarantee.
// All Rights Reserved.
//
// This file is part of IXP Manager.
Expand All @@ -22,7 +22,7 @@

// variables - you need to change these!
$key="your-api-key";
$url="https://ixp.example.com/ixp/api/v4/router/updated-before";
$url="https://ixp.example.com/api/v4/router/updated";
$threshold=86400;

// is curl available?
Expand All @@ -33,17 +33,18 @@

// get the JSON of routers last updated >$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 );
}
Expand All @@ -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 ) . '. ';
Expand Down

0 comments on commit 8589d00

Please sign in to comment.