drush_nagios
nagios.inc
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * @file
5  * Helper functions for nagios commands
6  */
7 
8 /**
9  * @defgroup exit_status Exit states
10  * Numeric error status definitions
11  * Error code definitions for interpreting the current error status.
12  * @see drush_set_error(), drush_get_error(), drush_get_error_log(), drush_cmp_error()
13  * @{
14  */
15 
16 /**
17  * Status 0 for nagios OK
18  * @var int NAGIOS_OK
19  */
20 define('NAGIOS_OK', 0);
21 
22 /**
23  * Status 1 for nagios warning
24  * @var int NAGIOS_WARNING
25  */
26 define('NAGIOS_WARNING', 1);
27 
28 /**
29  * Status 2 for nagios critical
30  * @var int NAGIOS_CRITICAL
31  */
32 define('NAGIOS_CRITICAL', 2);
33 
34 /** @} */
35 
36 /**
37  * @defgroup helper_functions Helper functions
38  * Helper functions
39  * @{
40  */
41 
42 /**
43  * Get list of installed projects and return their update status information via drush functions
44  *
45  * @return $update_info
46  * An array provided by drush´s _pm_get_update_info()
47  *
48  * @see drush_get_extensions()
49  * @see drush_get_projects()
50  * @see _pm_get_update_info()
51  */
53 
54  drush_include_engine('update_info', 'drupal', NULL, DRUSH_BASE_PATH . '/commands/pm/update_info');
55  include(DRUSH_BASE_PATH . '/commands/pm/updatecode.pm.inc');
56 
57  drush_bootstrap_max();
58  // Get installed extensions and projects.
59  $extensions = drush_get_extensions();
60  $projects = drush_get_projects($extensions);
61 
62  // Set quiet due getting update status information produces unwanted output.
63  drush_set_option('quiet', 1, 'all');
64  drush_set_context('DRUSH_QUIET', 1);
65 
66  // Get update status information.
67  $update_info = _pm_get_update_info($projects);
68 
69  // Unset quiet.
70  drush_set_option('quiet', 0, 'all');
71  drush_set_context('DRUSH_QUIET', 0);
72 
73  return $update_info;
74 }
75 /**
76  * Get pending database update information
77  *
78  * @return array
79  * An array with an update indicator 'has_updates' (boolean)
80  * and an array 'db_updates' keyed on the corresponding modules which includes
81  * - pending, array of pending updates, keyed update number
82  * - start, update number
83  *
84  * Example:
85  * @code
86  * Array
87  * (
88  * [has_updates] => 1
89  * [db_updates] => Array
90  * (
91  * [system] => Array
92  * (
93  * [pending] => Array
94  * (
95  * [7073] => 7073 - Add binary to {file_managed}, in case system_update_7034() was run without it.
96  * [7074] => 7074 - This update has been removed and will not run.
97  * [7076] => 7076 - Convert menu_links query strings into arrays.
98  * [7077] => 7077 - Revert {file_managed}.filename changed to a binary column.
99  * [7078] => 7078 - Add binary to {date_formats}.format.
100  * )
101  *
102  * [start] => 7073
103  * )
104  *
105  * [dblog] => Array
106  * (
107  * [pending] => Array
108  * (
109  * [7002] => 7002 - Add an index to the severity column in the watchdog database table.
110  * )
111  *
112  * [start] => 7002
113  * )
114  *
115  * [field] => Array
116  * (
117  * [pending] => Array
118  * (
119  * [7002] => 7002 - Split the all-inclusive field_bundle_settings variable per bundle.
120  * [7003] => 7003 - Add the FieldInfo class to the class registry.
121  * )
122  *
123  * [start] => 7002
124  * )
125  * [locale] => Array
126  * (
127  * [pending] => Array
128  * (
129  * [7004] => 7004 - Remove duplicates in {locales_source}.
130  * [7005] => 7005 - Increase {locales_languages}.formula column's length.
131  * )
132  *
133  * [start] => 7004
134  * )
135  *
136  * [node] => Array
137  * (
138  * [pending] => Array
139  * (
140  * [7013] => 7013 - Change {node}.vid default value from 0 to NULL to avoid deadlock issues on MySQL.
141  * )
142  *
143  * [start] => 7013
144  * )
145  *
146  * [user] => Array
147  * (
148  * [pending] => Array
149  * (
150  * [7018] => 7018 - Ensure there is an index on {users}.picture.
151  * )
152  *
153  * [start] => 7018
154  * )
155  *
156  * )
157  *
158  *)
159  * @endcode
160  * @see update_main_prepare()
161  * @see update_get_update_list()
162  * @see drupal_get_schema_versions()
163  */
165  $has_updates = FALSE;
166  $update_info = array();
167  drush_include_engine('drupal', 'update', drush_drupal_major_version());
168  if (drush_drupal_major_version() == 7) {
169  update_main_prepare();
170  $pending = update_get_update_list();
171  if (count($pending) != 0) {
172  $has_updates = TRUE;
173  }
174  }
175  else if(drush_drupal_major_version() == 6) {
176  update_main_prepare();
177 
178  $start = array();
179  $modules = drupal_get_installed_schema_version(NULL, FALSE, TRUE);
180  foreach ($modules as $module => $schema_version) {
181  $updates = drupal_get_schema_versions($module);
182  // Skip incompatible module updates completely, otherwise test schema versions.
183  if (!update_check_incompatibility($module) && $updates !== FALSE && $schema_version >= 0) {
184  // module_invoke returns NULL for nonexisting hooks, so if no updates
185  // are removed, it will == 0.
186  $last_removed = module_invoke($module, 'update_last_removed');
187  if ($schema_version < $last_removed) {
188  drush_set_error('PROVISION_DRUPAL_UPDATE_FAILED', dt( $module . ' module can not be updated. Its schema version is ' . $schema_version . '. Updates up to and including ' . $last_removed . ' have been removed in this release. In order to update ' . $module . ' module, you will first <a href="http://drupal.org/upgrade">need to upgrade</a> to the last version in which these updates were available.'));
189  continue;
190  }
191 
192  $updates = drupal_map_assoc($updates);
193  foreach (array_keys($updates) as $update) {
194  if ($update > $schema_version) {
195  $start[$module] = $update;
196  break;
197  }
198  }
199 
200  // Record any pending updates. Used for confirmation prompt.
201  foreach (array_keys($updates) as $update) {
202  if ($update > $schema_version) {
203  if (class_exists('ReflectionFunction')) {
204  // The description for an update comes from its Doxygen.
205  $func = new ReflectionFunction($module . '_update_' . $update);
206  $description = str_replace(array("\n", '*', '/'), '', $func->getDocComment());
207  }
208  if (empty($description)) {
209  $description = dt('description not available');
210  }
211 
212  $pending[$module][] = array("$update - " . trim($description));
213  $has_updates = TRUE;
214  }
215  }
216  }
217  }
218  }
219  $update_info['has_updates'] = $has_updates;
220  $update_info['db_updates'] = $pending;
221 
222  return $update_info;
223 }
224 
225 
226 /**
227  * Parses supplied update info and get type of update and corresponding informations
228  *
229  * @param array $update_info
230  * Update information
231  *
232  * @retval array
233  *
234  * An array with an update indicator 'has_updates' (boolean)
235  * and keyed on the following serverities which contain the corresponding projects
236  * - updates
237  * - security_updates
238  * - not_supported
239  * - ignored (ignore Option)
240  * - update_not_checked
241  * - update_revoked
242  * - up_to_date
243  * - unknown
244  *
245  * Projects array keys
246  * - project_type
247  * - existing_version
248  * - latest_version
249  * - release_link
250  * - severity
251  *
252  * Example called with --ignore=cnr,devel :
253  *
254  * @code
255  * Array
256  * (
257  * [has_updates] => 1
258  * [updates] => Array
259  * (
260  * [mimemail] => Array
261  * (
262  * [project_type] => module
263  * [existing_version] => 7.x-1.x-dev
264  * [latest_version] => 7.x-1.x-dev
265  * [release_link] => http://drupal.org/node/95867
266  * [severity] => Aktualisierung verfügbar
267  * )
268  *
269  * [password_policy] => Array
270  * (
271  * [project_type] => module
272  * [existing_version] => 7.x-1.0-beta1
273  * [latest_version] => 7.x-1.0-beta2
274  * [release_link] => http://drupal.org/node/1331478
275  * [severity] => Aktualisierung verfügbar
276  * )
277  *
278  * )
279  *
280  * [security_updates] => Array
281  * (
282  * [ckeditor] => Array
283  * (
284  * [project_type] => module
285  * [existing_version] => 7.x-1.3
286  * [latest_version] => 7.x-1.6
287  * [release_link] => http://drupal.org/node/1337106
288  * [severity] => SECURITY UPDATE available
289  * )
290  *
291  * )
292  *
293  * [not_supported] => Array
294  * (
295  * )
296  *
297  * [ignored] => Array
298  * (
299  * )
300  *
301  * [update_not_checked] => Array
302  * (
303  * )
304  *
305  * [update_revoked] => Array
306  * (
307  * )
308  *
309  * [ignored] => Array
310  * (
311  * [cnr] => Array
312  * (
313  * [project_type] => module
314  * [existing_version] => 7.x-4.1
315  * [latest_version] => 7.x-4.22
316  * [release_link] => http://drupal.org/node/1344032
317  * [severity] => Aktualisierung verfügbar
318  * )
319  *
320  * [devel] => Array
321  * (
322  * [project_type] => module
323  * [existing_version] => 7.x-1.0
324  * [latest_version] => 7.x-1.2
325  * [release_link] => http://drupal.org/node/1226936
326  * [severity] => SECURITY UPDATE available
327  * )
328  *
329  * )
330  * [up_to_date] => Array
331  * (
332  * [drupal] => Array
333  * (
334  * [project_type] => core
335  * [existing_version] => 7.9
336  * [latest_version] => 7.9
337  * [release_link] => http://drupal.org/node/1322736
338  * [severity] => Aktualisierung verfügbar
339  * )
340  *
341  * )
342  *
343  * )
344  * @endcode
345  */
346 function _nagios_parse_update_info($update_info) {
347 
348  $updates = array();
349 
350  // Update indicator.
351  $updates['has_updates'] = FALSE;
352 
353  // Serverities
354  $updates['updates'] = array();
355  $updates['security_updates'] = array();
356  $updates['not_supported'] = array();
357  $updates['ignored'] = array();
358  $updates['update_not_checked'] = array();
359  $updates['update_revoked'] = array();
360  $updates['up_to_date'] = array();
361  $updates['unknown'] = array();
362 
363  $ignore = array();
364  $ignore = explode(',', drush_get_option('ignore'));
365 
366  foreach($update_info as $project) {
367 
368  // Severity / Type of update.
369  ob_start();
370  $update_type = pm_update_filter($project);
371  ob_end_clean();
372 
373  // maschine readable name of the project.
374  $project_name = $project['name'];
375 
376  // Create array to append it later.
377  $update = array();
378  $update['project_type'] = $project['project_type'];
379  $update['existing_version'] = $project['existing_version'];
380 
381  // Skip building array on these serverities...
382  if ($update_type != dt('Unknown') || $update_type != dt('Unable to check status')) {
383  $update['latest_version'] = $project['latest_version'];
384  $update['release_link'] = $project['releases'][$project['latest_version']]['release_link'];
385  $update['severity'] = dt($update_type);
386  }
387 
388  // Add projects which are locked through `drush pm-update --lock` to ingnore array.
389  if (drush_get_option('ignore-locked')) {
390  if (isset($project['path'])) {
391  $lockfile = $drupal_root . '/' . $project['path'] . '/.drush-lock-update';
392  if (file_exists(getcwd() . $lockfile)) {
393  $ignore[] = $project_name;
394  }
395  }
396  }
397 
398  // Add projects from ignore array to $updates['ignored'] and skip this loop iteration.
399  if (in_array($project_name, $ignore)) {
400  $updates['ignored'][$project_name] = $update;
401  continue;
402  }
403 
404  // Get severity of update and append it to the array.
405  switch ($update_type) {
406  case dt('Update available') :
407  $updates['updates'][$project_name] = $update;
408  $updates['has_updates'] = TRUE;
409  break;
410  case dt('SECURITY UPDATE available'):
411  $updates['security_updates'][$project_name] = $update;
412  $updates['has_updates'] = TRUE;
413  break;
414  case dt('Installed version not supported'):
415  $updates['not_supported'][$project_name] = $update;
416  $updates['has_updates'] = TRUE;
417  break;
418  case dt('Unable to check status'):
419  $updates['update_not_checked'][$project_name] = $update;
420  break;
421  case dt('Installed version REVOKED'):
422  $updates['update_revorked'][$project_name] = $update;
423  $updates['has_updates'] = TRUE;
424  break;
425  case dt('Up to date'):
426  $updates['up_to_date'][$project_name] = $update;
427  break;
428  default:
429  $updates['unknown'][$project_name] = $update;
430  break;
431  }
432  }
433  return $updates;
434 }
435 
436 
437 /**
438  * Get Drupals status and requirement informations.
439  *
440  * @return array
441  * An array key on requirement, which contains at least:
442  * - title, Readable status/requirement
443  * - value, its value
444  * Optional:
445  * - severity, Status code
446  * - description, more details
447  * - weight
448  * @code
449  * Array
450  * (
451  * [drupal] => Array
452  * (
453  * [title] => Drupal
454  * [value] => 6.33
455  * [severity] => -1
456  * [weight] => -10
457  * )
458  *
459  * [webserver] => Array
460  * (
461  * [title] => Web server
462  * [value] => Apache/2.4.10 (Debian)
463  * )
464  *
465  * [php] => Array
466  * (
467  * [title] => PHP
468  * [value] => <a href="/admin/reports/status/php">5.6.0-1</a>
469  * )
470  *
471  * [php_register_globals] => Array
472  * (
473  * [title] => PHP register globals
474  * [value] => Disabled
475  * )
476  *
477  * [php_memory_limit] => Array
478  * (
479  * [title] => PHP memory limit
480  * [value] => 128M
481  * )
482  *
483  * [mysql] => Array
484  * (
485  * [title] => MySQL database
486  * [value] => <a href="/admin/reports/status/sql">5.5.39</a>
487  * )
488  *
489  * [settings.php] => Array
490  * (
491  * [value] => Protected
492  * [title] => Configuration file
493  * )
494  *
495  * [files_htaccess] => Array
496  * (
497  * [title] => Files directory
498  * [value] => Not fully protected
499  * [severity] => 2
500  * [description] => See <a href="http://drupal.org/SA-CORE-2013-003">http://drupal.org/SA-CORE-2013-003</a> for information about the recommended .htaccess file which should be added to the <em>sites/netzaffe.de/files</em> directory to help protect against arbitrary code execution.
501  * )
502  *
503  * [cron] => Array
504  * (
505  * [title] => Cron maintenance tasks
506  * [severity] => 0
507  * [value] => Last run 1 hour 18 min ago
508  * [description] => You can <a href="/admin/reports/status/run-cron">run cron manually</a>.
509  * )
510  *
511  * [file system] => Array
512  * (
513  * [title] => File system
514  * [value] => Writable (<em>public</em> download method)
515  * )
516  *
517  * [update] => Array
518  * (
519  * [title] => Database updates
520  * [severity] => 0
521  * [value] => Up to date
522  * )
523  *
524  * [update access] => Array
525  * (
526  * [value] => Protected
527  * [title] => Access to update.php
528  * )
529  *
530  * [unicode] => Array
531  * (
532  * [title] => Unicode library
533  * [value] => PHP Mbstring Extension
534  * [severity] => 0
535  * )
536  *
537  * [update status] => Array
538  * (
539  * [value] => Enabled
540  * [title] => Update notifications
541  * )
542  *
543  * [http requests] => Array
544  * (
545  * [title] => HTTP request status
546  * [value] => Fails
547  * [severity] => 2
548  * [description] => Your system or network configuration does not allow Drupal to access web pages, resulting in reduced functionality. This could be due to your webserver configuration or PHP settings, and should be resolved in order to download information about available updates, fetch aggregator feeds, sign in via OpenID, or use other network-dependent services.
549  * )
550  *
551  * [update_core] => Array
552  * (
553  * [title] => Drupal core update status
554  * [value] => No update data available
555  * [severity] => 1
556  * [reason] => -2
557  * [description] => No information is available about potential new releases for currently installed modules and themes. To check for updates, you may need to <a href="/admin/reports/status/run-cron?destination=admin%2Fsettings%2Flanguage">run cron</a> or you can <a href="/admin/reports/updates/check?destination=admin%2Fsettings%2Flanguage">check manually</a>. Please note that checking for available updates can take a long time, so please be patient.
558  * )
559  *
560  * [captcha_wrong_response_counter] => Array
561  * (
562  * [title] => CAPTCHA
563  * [value] => Already 61082 blocked form submissions
564  * [severity] => -1
565  * )
566  *
567  * [0] => Array
568  * (
569  * [title] => GeSHi filter
570  * [value] => Found GeSHi library version <em>1.0.8</em>
571  * [severity] => 0
572  * )
573  *
574  * [image_import_dir] => Array
575  * (
576  * [title] => Image import
577  * [value] => Import directory <em>sites/netzaffe.de/files/images/import</em> does not exist or is not writable.
578  * [description] => The import directory <em>sites/netzaffe.de/files/images/import</em> either does not exist or does not grant the web container write permission. Either <a href="/admin/settings/image/image_import">choose</a> a different directory or create the <em>sites/netzaffe.de/files/images/import</em> directory and grant write permissions. The Image import module will not function until this is corrected.
579  * [severity] => 2
580  * )
581  *
582  * [image_toolkit] => Array
583  * (
584  * [value] => The <em>gd</em> toolkit is installed.
585  * [severity] => 0
586  * [title] => Image toolkit
587  * )
588  *
589  * [image_dirs] => Array
590  * (
591  * [value] => Exists (<em>sites/netzaffe.de/files/images</em>).
592  * [severity] => 0
593  * [title] => Image module directories
594  * )
595  *
596  * [page_title_version] => Array
597  * (
598  * [title] => Page title version
599  * [value] => Enabled (<code>page_title</code> table contains 0 rows)
600  * [severity] => 0
601  * )
602  *
603  * [tagadelic] => Array
604  * (
605  * [severity] => 0
606  * [title] => Tagadelic
607  * [value] => No incompatible modules enabled.
608  * )
609  *
610  * [xmlsitemap_directory] => Array
611  * (
612  * [title] => XML sitemap cache directory
613  * [value] => Writable
614  * )
615  *
616  * [xmlsitemap_generated] => Array
617  * (
618  * [title] => XML sitemap
619  * [value] => Last attempted generation on 2014-10-25 14:34 (1 hour 18 min ago).
620  * [severity] => 0
621  * )
622  *
623  * )
624  * @endcode
625  *
626  * @see <a href="https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_status/7">system_status()</a>
627  */
629  include_once './includes/install.inc';
630  drupal_load_updates();
631 
632  // Check run-time requirements and status information.
633  $requirements = module_invoke_all('requirements', 'runtime');
634 
635  return $requirements;
636 }
637 
638 /**
639  * Parses the requirements by _nagios_get_drupal_status_info()
640  *
641  * @return array
642  * An associative array with uneeded drupal requirements with requirement_violation as indicator
643  * and items grouped by their severities(requirement_warning, requirement_error) and ignored.
644  * @code
645  * Array
646  * (
647  * [requirement_violation] => 1
648  * [requirement_warning] => Array
649  * (
650  * [cron] => Array
651  * (
652  * [title] => Cron maintenance tasks
653  * [value] => Last run 1 week 2 days ago
654  * [description] => You can <a href="/admin/reports/status/run-cron">run cron manually</a>.
655  * [severity] => 1
656  * )
657  *
658  * [xmlsitemap_generated] => Array
659  * (
660  * [title] => XML sitemap
661  * [value] => Last attempted generation on 2014-10-25 14:34 (1 week 2 days ago).
662  * [severity] => 1
663  * )
664  * )
665  * [requirement_error] => Array
666  * (
667  * [files_htaccess] => Array
668  * (
669  * [title] => Files directory
670  * [value] => Not fully protected
671  * [description] => See <a href="http://drupal.org/SA-CORE-2013-003">http://drupal.org/SA-CORE-2013-003</a> for information about the recommended .htaccess file which should be added to the <em>sites/netzaffe.de/files</em> directory to help protect against arbitrary code execution.
672  * [severity] => 2
673  * )
674  *
675  *
676  * [http requests] => Array
677  * (
678  * [title] => HTTP request status
679  * [value] => Fails
680  * [description] => Your system or network configuration does not allow Drupal to access web pages, resulting in reduced functionality. This could be due to your webserver configuration or PHP settings, and should be resolved in order to download information about available updates, fetch aggregator feeds, sign in via OpenID, or use other network-dependent services.
681  * [severity] => 2
682  * )
683  * )
684  *
685  * [ignored] => Array
686  * (
687  * [unicode] => Array
688  * (
689  * [title] => Unicode library
690  * [value] => Error
691  * [severity] => 2
692  * )
693  * )
694  * )
695  * @endcode
696  *
697  * @see <a href="https://api.drupal.org/api/drupal/includes%21install.inc/7">install.inc</a>
698  */
699 function _nagios_parse_drupal_status_info($requirements) {
700  $parsed_requirements = array();
701  $ignore = drush_get_option('ignore', NULL);
702  $ignore = isset($ignore) ? explode(',', $ignore) : array();
703  foreach ($requirements as $key => $requirement) {
704  if (array_key_exists('severity', $requirement) && !array_key_exists('reason', $requirement)) {
705  if (in_array($key, $ignore)) {
706  $parsed_requirements['ignored'][$key] = $requirement;
707  continue;
708  }
709  if ($requirement['severity'] != 0 || $requirement['severity'] != -1) {
710  if ($requirement['severity'] == 1) {
711  $parsed_requirements['requirement_violation'] = TRUE;
712  $parsed_requirements['requirement_warning'][$key] = $requirement;
713  }
714  if ($requirement['severity'] == 2) {
715  $parsed_requirements['requirement_violation'] = TRUE;
716  $parsed_requirements['requirement_error'][$key] = $requirement;
717  }
718  }
719  }
720  }
721  return $parsed_requirements;
722 }
723 
724 /**
725  * Monitores a single Drupal site for module and core updates
726  *
727  * Print a message for nagios
728  *
729  * @retval void
730  */
731 function _nagios_print_message($parsed_update_info) {
732 
733  // Message prefix
734  $status_msg = dt('!site_root: ',
735  array(
736  '!site_root'=> drush_get_context('DRUSH_DRUPAL_ROOT') . '/' . drush_get_context('DRUSH_DRUPAL_SITE_ROOT'),
737  )
738  );
739  // Build updates message...
740 
741  // Check indicator variables...
742  if ($parsed_update_info['has_updates'] || $parsed_update_info['requirement_violation']) {
743  $command = drush_get_command();
744  switch ($command['command']) {
745  // Pending database updates message.
746  case 'check-db-updates':
747  if (count($parsed_update_info['db_updates'])) {
748  $status_msg .= dt('has pending database updates, run \'drush updatedb\' or visit update.php in your browser for more details.');
749  }
750  break;
751  // Module and core updates message.
752  case 'check-updates':
753  unset($parsed_update_info['has_updates']);
754  // Traverse serverities
755  foreach ($parsed_update_info as $severity => $projects){
756 
757  // Skip empty and uneeded serverities
758  if (count($projects) == 0 || $erverity == 'up_to_date' || $severity == 'unknown') {
759  continue;
760  }
761  $ignored = array();
762  if ($severity == 'ignored') {
763  foreach ($projects as $name => $project) {
764  $ignored[] = $name . '(' . $project['severity'] . ')';
765  }
766  $status_msg .= dt(' IGNORED BY SETTINGS: !modules',
767  array(
768  '!modules' => implode(',', $ignored),
769  )
770  );
771  }
772  else {
773  $status_msg .= dt(' !type: !modules',
774  array(
775  '!type' => strtoupper(str_replace('_', ' ', $severity)),
776  '!modules' => implode(',', array_keys($projects)),
777  )
778  );
779  }
780  }
781  break;
782  case 'check-drupal-requirements':
783  unset($parsed_update_info['requirement_violation']);
784 
785  // Traverse serverities
786  foreach ($parsed_update_info as $severity => $requirements){
787  $ignored = array();
788  if ($severity == 'ignored') {
789  foreach ($requirements as $name => $requirement) {
790  $ignored[] = $name . '(' . $requirement['severity'] . ')';
791  }
792  $status_msg .= dt(' IGNORED BY SETTINGS: !requirements',
793  array(
794  '!requirements' => implode(',', $ignored),
795  )
796  );
797  }
798  else {
799  $status_msg .= dt(' !type: !requirements',
800  array(
801  '!type' => strtoupper(str_replace('_', ' ', $severity)),
802  '!requirements' => implode(',', array_keys($requirements)),
803  )
804  );
805  }
806  }
807  break;
808  }
809  }
810  else {
811  // Ok message with ignored.cd
812  if ($parsed_update_info['ignored']) {
813  foreach ($parsed_update_info as $severity => $requirements) {
814  $ignored = array();
815  if ($severity == 'ignored') {
816  foreach ($requirements as $name => $requirement) {
817  $ignored[] = $name . '(' . $requirement['severity'] . ')';
818  }
819  $status_msg .= dt('Everythings OK, IGNORED BY SETTINGS: !requirements',
820  array(
821  '!requirements' => implode(',', $ignored),
822  )
823  );
824  }
825  }
826  }
827  // OK message,
828  else {
829  $status_msg = $status_msg . dt('Everythings OK...');
830  }
831  }
832  // Print message
833  drush_print($status_msg);
834 }
835 
836 /**
837  * Return exit status for nagios
838  *
839  * @param array $parsed_update_info
840  *
841  * @retval int
842  * - NAGIOS_OK (0) if monitored site is up to date,
843  * - NAGIOS_WARNING (1) if there are updates, requirements warnings
844  * or unsupported modules available
845  * - NAGIOS_CRITICAL(2) if there are security or requirement warnings updates available
846  */
847 function _nagios_exit_status($parsed_update_info) {
848  if ($parsed_update_info['has_updates'] || $parsed_update_info['requirement_violation']) {
849  // Critical.
850  $critical = (count($parsed_update_info['security_updates']) != 0
851  || count($parsed_update_info['requirement_error']) != 0);
852  // Warning.
853  $updates = (count($parsed_update_info['updates']) != 0);
854  $not_supported = (count($parsed_update_info['not_supported']) != 0);
855  $db_updates = (count($parsed_update_info['db_updates']) != 0);
856  $requirements_warnings = (count($parsed_update_info['requirement_warning']) != 0);
857 
858  if ($critical) {
859  return NAGIOS_CRITICAL;
860  }
861  elseif ($updates || $not_supported || $db_updates || $requirements_warnings) {
862  return NAGIOS_WARNING;
863  }
864  }
865  else {
866  return NAGIOS_OK;
867  }
868 }
869 
870 /** @} */
_nagios_exit_status($parsed_update_info)
Definition: nagios.inc:847
const NAGIOS_WARNING
Definition: nagios.inc:26
_nagios_print_message($parsed_update_info)
Definition: nagios.inc:731
_nagios_parse_drupal_status_info($requirements)
Definition: nagios.inc:699
_nagios_get_update_info()
Definition: nagios.inc:52
const NAGIOS_OK
Definition: nagios.inc:20
_nagios_get_db_update_info()
Definition: nagios.inc:164
const NAGIOS_CRITICAL
Definition: nagios.inc:32
_nagios_get_drupal_status_info()
Definition: nagios.inc:628
_nagios_parse_update_info($update_info)
Definition: nagios.inc:346