You are here

function nagios_updates in Nagios Monitoring 8

Same name and namespace in other branches
  1. 6 nagios.drush.inc \nagios_updates()
  2. 7 nagios.drush.inc \nagios_updates()

Helper function for drush_nagios_updates().

Parameters

array[]|null $data:

Return value

array[]|null Status output in the hook_nagios() format, keyed by $project_name.

1 call to nagios_updates()
drush_nagios_updates in ./nagios.drush.inc
Drush command callback: nagios-updates.

File

./nagios.drush.inc, line 211
Provides drush integration for the Nagios module.

Code

function nagios_updates($data) {
  if (!is_array($data)) {
    return NULL;
  }
  $updates = [];

  // Create an array of status values keyed by module or theme name, since
  // we'll need this while generating the report if we have to cross reference
  // anything (e.g. subthemes which have base themes missing an update).
  foreach ($data as $project) {
    foreach ($project['includes'] as $key => $name) {
      $status[$key] = $project['status'];
    }
  }
  foreach ($data as $project) {
    if ($project['status'] == UpdateManagerInterface::NOT_SECURE || $project['status'] == UpdateManagerInterface::NOT_CURRENT) {
      $security_class = [];
      $version_class = [];
      if (isset($project['recommended']) && ($project['status'] != UpdateManagerInterface::CURRENT || $project['existing_version'] !== $project['recommended'])) {

        // First, figure out what to recommend.
        // If there's only 1 security update and it has the same version we're
        // recommending, give it the same CSS class as if it was recommended,
        // but don't print out a separate "Recommended" line for this project.
        if (!empty($project['security updates']) && count($project['security updates']) == 1 && $project['security updates'][0]['version'] === $project['recommended']) {
          $security_class[] = 'version-recommended';
          $security_class[] = 'version-recommended-strong';
        }
        else {
          $version_class[] = 'version-recommended';

          // Apply an extra class if we're displaying both a recommended
          // version and anything else for an extra visual hint.
          if (!empty($project['also']) || $project['recommended'] !== $project['latest_version'] || $project['install_type'] == 'dev' && isset($project['dev_version']) && $project['latest_version'] !== $project['dev_version'] && $project['recommended'] !== $project['dev_version'] || isset($project['security updates'][0]) && $project['recommended'] !== $project['security updates'][0]) {
            $version_class[] = 'version-recommended-strong';
          }
        }
      }
      $row_key = mb_strtolower($project['name']);
      if (!isset($updates[$row_key])) {
        $updates[$row_key] = [];
      }
      $updates[$row_key]['type'] = $project['project_type'];
      $updates[$row_key]['status'] = $project['status'];
    }
  }
  return $updates;
}