-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NF] Nagios script to check for any routers stuck in locked state
- Loading branch information
Showing
3 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
tools/runtime/route-servers/nagios-check-locked-routers.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
// Copyright (C) 2009 - 2024 Internet Neutral Exchange Association Company Limited By Guarantee. | ||
// All Rights Reserved. | ||
// | ||
// This file is part of IXP Manager. | ||
// | ||
// IXP Manager is free software: you can redistribute it and/or modify it | ||
// under the terms of the GNU General Public License as published by the Free | ||
// Software Foundation, version 2.0 of the License. | ||
// | ||
// IXP Manager is distributed in the hope that it will be useful, but WITHOUT | ||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
// more details. | ||
// | ||
// You should have received a copy of the GNU General Public License v2.0 | ||
// along with IXP Manager. If not, see: | ||
// | ||
// http://www.gnu.org/licenses/gpl-2.0.html | ||
// | ||
|
||
// variables - you need to change these! | ||
$key="your-api-key"; | ||
$url="https://ixp.example.com/api/v4/router/locked-longer-than"; | ||
$threshold=7200; | ||
|
||
// is curl available? | ||
if( !function_exists( 'curl_init' ) ) { | ||
echo "UNKNOWN: curl not available - install php-curl"; | ||
exit( 3 ); | ||
} | ||
|
||
// get the JSON of routers last updated >$threshold seconds ago | ||
$s = curl_init(); | ||
curl_setopt( $s, CURLOPT_URL, $url . '/' . $threshold ); | ||
curl_setopt( $s, CURLOPT_HTTPHEADER, [ 'X-IXP-Manager-API-Key: ' . $key ] ); | ||
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( $json === "[]" ) { | ||
echo sprintf( "OK: no routers stuck mid-configuration for >%d seconds\n", $threshold ); | ||
exit(0); | ||
} | ||
|
||
if( !( $routers = json_decode( $json ) ) ) { | ||
echo "UNKNOWN: could not decode JSON response from API\n"; | ||
exit( 3 ); | ||
} | ||
|
||
$bad = []; | ||
foreach( $routers as $handle => $r ) { | ||
$bad[] = $handle; | ||
} | ||
|
||
echo 'ERROR: the following router(s) have been locked for more than ' . $threshold . 'secs: ' . implode( ', ', $bad ) . ".\n"; | ||
exit(2); |