Created
December 22, 2013 17:09
-
-
Save bfritscher/8085491 to your computer and use it in GitHub Desktop.
Nagios check plugin for wordpress
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
#!/usr/bin/env php | |
<?php | |
/** | |
source: http://www.monitoringexchange.org/inventory/Check-Plugins/Software/HTTP-%2526-FTP/Check-Wordpress-Versions | |
modified by: Boris Fritscher | |
**/ | |
if($argc != 2) { | |
print "usage: check_wp_versions.php <path to wp installation>\n"; | |
exit(1); | |
} | |
#bug fix for cli include of wp-load | |
define("WP_INSTALLING", false); | |
chdir($argv[1]); | |
require_once('./wp-load.php'); | |
global $wp_version; | |
$core_updates = 0; | |
$plugin_updates = 0; | |
wp_version_check(); | |
wp_update_plugins(); | |
#wp_update_themes(); | |
$core = get_transient('update_core'); | |
$plugins = get_transient('update_plugins'); | |
#$themes = get_transient('update_themes'); | |
$core_updates = 0; | |
$core_text = ""; | |
foreach($core->updates as $update) { | |
if($update->current != $wp_version) { | |
$core_text .= "WordPress Update: ".$update->current."<br />"; | |
$core_updates++; | |
} | |
} | |
$plugin_updates = 0; | |
$plugin_text = ""; | |
foreach($plugins->response as $plgupd) { | |
$plugin_text .= $plgupd->slug ." (" . $plgupd->new_version . ")<br/>"; | |
$plugin_updates++; | |
} | |
if($core_updates > 0) { | |
$text = "$core_updates core updates available!"; | |
} else { | |
$text = "core ok"; | |
} | |
if($plugin_updates > 0) { | |
$text .= " ; $plugin_updates plugins updates are available!"; | |
} else { | |
$text .= " ; plugins ok"; | |
} | |
$text .= " | Installed WordPress: " . $wp_version . "<br />" | |
. $core_text . $plugin_text; | |
if($core_updates > 0) { | |
print("CRITICAL - " . $text); | |
exit(2); | |
} else if($plugin_updates > 0) { | |
print("WARNING - " . $text); | |
exit(1); | |
} else { | |
print("OK - " . $text); | |
exit(0); | |
} | |
print("CRITICAL - Error in check_wp_versions.php"); | |
exit(2); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment