function drush_nagios_updates in Nagios Monitoring 6
Same name and namespace in other branches
- 8 nagios.drush.inc \drush_nagios_updates()
- 7 nagios.drush.inc \drush_nagios_updates()
Drush command callback: nagios-updates.
Parameters
string $update_type: A string containing:
- 'all' to list all updates.
- 'security' to list security updates only.
integer $nagios_flag: Send 'nagios' to prefix the output with a Nagios string.
File
- ./
nagios.drush.inc, line 96
Code
function drush_nagios_updates($update_type = NULL, $nagios_flag = NULL) {
$flag_insecure = FALSE;
$exit_status = NULL;
$message = '';
if ($available = update_get_available(TRUE)) {
module_load_include('inc', 'update', 'update.compare');
$data = update_calculate_project_data($available);
// Unset any data referencing projects we're not interested in.
$nagios_ignored_modules = variable_get('nagios_ignored_modules', array());
$nagios_ignored_themes = variable_get('nagios_ignored_themes', array());
$nagios_ignored_projects = $nagios_ignored_modules + $nagios_ignored_themes;
foreach ($nagios_ignored_projects as $key => $value) {
if ($value == TRUE && isset($data[$key])) {
unset($data[$key]);
}
}
$module_list = array();
$updates = nagios_updates($data);
if (count($updates)) {
foreach ($updates as $project_name => $update_info) {
// In any case we need to flag security updates.
if ($update_info['status'] == UPDATE_NOT_SECURE) {
$flag_insecure = TRUE;
$module_list[] = $project_name;
}
elseif ($update_type && $update_type == 'all') {
$module_list[] = $project_name;
}
}
if ($nagios_flag == 'nagios') {
if ($flag_insecure) {
// Returning the value didn't work in drush 5.x, so we print it instead.
$message = 'ADMIN CRITICAL - Updates required for: ' . implode(' ', $module_list);
$exit_status = 2;
}
else {
if (empty($module_list)) {
$message = 'ADMIN WARNING - Updates required, but no security updates.';
}
else {
$message = 'ADMIN WARNING - Updates required for: ' . implode(' ', $module_list);
}
$exit_status = 1;
}
}
else {
$message = implode(' ', $module_list);
}
}
}
if ($nagios_flag == 'nagios' && is_null($exit_status)) {
$message = 'OK - No updates';
}
drush_set_context('DRUSH_EXECUTION_COMPLETED', TRUE);
drush_print($message);
exit($exit_status);
}