Application State Icons (#11630)

This commit is contained in:
SourceDoctor 2020-05-20 02:21:02 +02:00 committed by GitHub
parent cbb0b5219e
commit b41d262537
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 107 additions and 7 deletions

View File

@ -31,6 +31,45 @@ use LibreNMS\Config;
class Html
{
/**
* return icon and color for application state
* @param string $app_state
* @return array
*
*/
public static function appStateIcon($app_state)
{
switch ($app_state) {
case 'OK':
$icon = '';
$color = '';
$hover_text = 'OK';
break;
case 'ERROR':
$icon = 'fa-close';
$color = '#cc1122';
$hover_text = 'Error';
break;
case 'LEGACY':
$icon = 'fa-warning';
$color = '#eebb00';
$hover_text = 'legacy Agent Script';
break;
case 'UNSUPPORTED':
$icon = 'fa-flash';
$color = '#ff9900';
$hover_text = 'Unsupported Agent Script Version';
break;
default:
$icon = 'fa-question';
$color = '#777777';
$hover_text = 'Unknown State';
break;
}
return ['icon' => $icon, 'color' => $color, 'hover_text' => $hover_text];
}
/**
* Print or return a row of graphs
*

View File

@ -49,8 +49,8 @@ class ObjectCache
{
return Cache::remember('ObjectCache:applications_list:' . auth()->id(), self::$cache_time, function () {
return Application::hasAccess(auth()->user())
->select('app_type', 'app_instance')
->groupBy('app_type', 'app_instance')
->select('app_type', 'app_state', 'app_instance')
->groupBy('app_type', 'app_state', 'app_instance')
->get()
->sortBy('show_name', SORT_NATURAL|SORT_FLAG_CASE)
->groupBy('app_type');

View File

@ -341,12 +341,22 @@ $link_array = array(
'device' => $device['device_id'],
'tab' => 'apps',
);
$apps = \LibreNMS\Util\ObjectCache::applications()->flatten();
foreach ($apps as $app) {
$app_state = \LibreNMS\Util\Html::appStateIcon($app->app_state);
if (!empty($app_state['icon'])) {
$app_state_info = "<font color=\"".$app_state['color']."\"><i title=\"".$app_state['hover_text']."\" class=\"fa ".$app_state['icon']." fa-fw fa-lg\" aria-hidden=\"true\"></i></font>";
} else {
$app_state_info = '';
}
echo $sep;
if ($vars['app'] == $app->app_type) {
echo "<span class='pagemenu-selected'>";
}
echo $app_state_info;
echo generate_link($app->displayName(), array('page' => 'apps', 'app' => $app->app_type));
if ($vars['app'] == $app->app_type) {
echo '</span>';

View File

@ -17,10 +17,18 @@ $apps = Application::query()->hasAccess(Auth::user())->where('app_type', $vars['
});
foreach ($apps as $app) {
$app_state = \LibreNMS\Util\Html::appStateIcon($app['app_state']);
if (!empty($app_state['icon'])) {
$app_state_info = "<font color=\"".$app_state['color']."\"><i title=\"".$app_state['hover_text']."\" class=\"fa ".$app_state['icon']." fa-fw fa-lg\" aria-hidden=\"true\"></i></font>";
} else {
$app_state_info = '';
}
echo '<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
'. Url::deviceLink($app->device, null, ['tab' => 'apps', 'app' => $app->app_type]).'
<h3 class="panel-title">'.
$app_state_info.
Url::deviceLink($app->device, null, ['tab' => 'apps', 'app' => $app->app_type]).'
<div class="pull-right"><small class="muted">'.$app->app_instance.' '.$app->app_status.'</small></div>
</h3>
</div>

View File

@ -29,7 +29,10 @@ foreach (Application::query()->hasAccess(Auth::user())->with('device')->get()->s
$overlib_url = route('device', [$app->device_id, 'apps', "app=$app->app_type"]);
$overlib_link = '<span style="float:left; margin-left: 10px; font-weight: bold;">'.optional($app->device)->shortDisplayName().'</span>';
$app_state = \LibreNMS\Util\Html::appStateIcon($app->app_state);
$app_state_info = "<font color=\"".$app_state['color']."\"><i title=\"".$app_state['hover_text']."\" class=\"fa ".$app_state['icon']." fa-fw fa-lg\" aria-hidden=\"true\"></i></font>";
$overlib_link = '<span style="float:left; margin-left: 10px; font-weight: bold;">'. $app_state_info . optional($app->device)->shortDisplayName().'</span>';
if (!empty($app->app_instance)) {
$overlib_link .= '<span style="float:right; margin-right: 10px; font-weight: bold;">'.$app->app_instance.'</span>';
$content_add = '('.$app->app_instance.')';

View File

@ -33,7 +33,15 @@ foreach ($app_list as $app) {
}
$link_add = array('app' => $app['app_type']);
$text = $app['app_display'];
$app_state = \LibreNMS\Util\Html::appStateIcon($app['app_state']);
if (!empty($app_state['icon'])) {
$text = "<font color=\"".$app_state['color']."\"><i title=\"".$app_state['hover_text']."\" class=\"fa ".$app_state['icon']." fa-fw fa-lg\" aria-hidden=\"true\"></i></font>";
} else {
$text = '';
}
$text .= $app['app_display'];
if (!empty($app['app_instance'])) {
$text .= '('.$app['app_instance'].')';
$link_add['instance'] = $app['app_id'];

View File

@ -555,7 +555,7 @@ function get_main_serial($device)
* The special group "none" will not be prefixed.
*
* @param array $app app from the db, including app_id
* @param string $response This should be the full output
* @param string $response This should be the return state of Application polling
* @param array $metrics an array of additional metrics to store in the database for alerting
* @param string $status This is the current value for alerting
*/
@ -577,13 +577,45 @@ function update_application($app, $response, $metrics = array(), $status = '')
'Traceback (most recent call last):',
))) {
$data['app_state'] = 'ERROR';
} elseif (in_array($response, ['OK', 'ERROR', 'LEGACY', 'UNSUPPORTED'])) {
$data['app_state'] = $response;
} else {
# should maybe be 'unknown' as state
$data['app_state'] = 'OK';
}
}
if ($data['app_state'] != $app['app_state']) {
$data['app_state_prev'] = $app['app_state'];
$device = dbFetchRow('SELECT * FROM devices LEFT JOIN applications ON devices.device_id=applications.device_id WHERE applications.app_id=?', array($app['app_id']));
$app_name = \LibreNMS\Util\StringHelpers::nicecase($app['app_type']);
# $severity 1: ok, 2: info, 3: notice, 4: warning, 5: critical, 0: unknown
switch ($data['app_state']) {
case 'OK':
$severity = 1;
$event_msg = "changed to OK";
break;
case 'ERROR':
$severity = 5;
$event_msg = "ends with ERROR";
break;
case 'LEGACY':
$severity = 4;
$event_msg = "Client Agent is deprecated";
break;
case 'UNSUPPORTED':
$severity = 5;
$event_msg = "Client Agent Version is not supported";
break;
default:
$severity = 0;
$event_msg = "has UNKNOWN state";
break;
}
log_event("Application ".$app_name." ".$event_msg, $device, 'application', $severity);
}
dbUpdate($data, 'applications', '`app_id` = ?', array($app['app_id']));