Skip to content

Commit

Permalink
agents: show icon if new checks found
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Nov 12, 2023
1 parent af3436c commit 76bcbc5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
23 changes: 20 additions & 3 deletions plugins/plugins-available/agents/lib/Thruk/Controller/agents.pm
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,29 @@ sub _process_show {
}
$c->stash->{data} = Thruk::Backend::Manager::sort_result({}, $hosts, ['_AGENT_SECTION', 'host_name', 'site']);

my $versions = $c->db->get_services(filter => [ Thruk::Utils::Auth::get_auth_filter( $c, 'hosts' ),
my $services = $c->db->get_services(filter => [ Thruk::Utils::Auth::get_auth_filter( $c, 'hosts' ),
'host_custom_variables' => { '~' => 'AGENT .+' },
'description' => 'agent version',
'description' => { '~' => '^(agent version|agent inventory)$' },
],
);
$c->stash->{versions} = Thruk::Base::array2hash($versions, "host_name");
my $info = {};
for my $svc (@{$services}) {
my $extra = $info->{$svc->{'host_name'}} // {};
if($svc->{'description'} eq 'agent version') {
my $v = $svc->{'plugin_output'};
$v =~ s/^.*\sv/v/gmx;
$extra->{'version'} = $v;
$extra->{'state'} = $svc->{'state'};
$extra->{'has_been_checked'} = $svc->{'has_been_checked'};
}
if($svc->{'description'} eq 'agent inventory') {
$extra->{'inv_state'} = $svc->{'state'};
$extra->{'inv_out'} = $svc->{'plugin_output'};
$extra->{'inv_out'} =~ s/^\w+\ \-\ //gmx;
}
$info->{$svc->{'host_name'}} = $extra;
}
$c->stash->{info} = $info;

# set fallback backend for start page so the apply button can be shown
if(!$c->req->parameters->{'backend'} && !$c->stash->{'param_backend'}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ sub _check_inventory {
(scalar @{$checks->{'new'}} != 1 ? 's' : ''),
$perfdata,
join("\n", @details),
), 2);
), 1);
}

my @details;
Expand Down
12 changes: 9 additions & 3 deletions plugins/plugins-available/agents/templates/agents.tt
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
<td><a class="link" href="status.cgi?host=[% h.name | uri %]">[% h.name | html %]</a></td>
<td>
[% state = 'PENDING' %]
[% IF versions.exists(hostname) %]
[% state = servicestatetext(versions.$hostname) %]
[% IF info.exists(hostname) %]
[% state = servicestatetext(info.$hostname) %]
[% END %]
<div class='text-center badge [% state %]'>[% state %]</div>
</td>
<td>[% peer_name(h) | html %]</td>
<td><img src="[% url_prefix %]plugins/[% plugin_name %]/images/[% agent.icon | html %]" alt="[% agent.type | html %]" width=20 height=20 class="inline"> [% agent.type | html %]</td>
<td>[% IF versions.exists(hostname) %][% versions.$hostname.plugin_output.replace('^.*\sv', 'v') | html %][% END %]</td>
<td>[% IF info.exists(hostname) && info.$hostname.exists("version") %][% info.$hostname.version | html %][% END %]</td>
<td>
<div class="flexrow flex-nowrap gap-x-2">
<a href="agents.cgi?action=edit&amp;hostname=[% h.name | uri %]&backend=[% h.peer_key | html %]"><i class="fa-solid fa-pencil text-sm" title='Edit this host'></i></a>
Expand All @@ -59,6 +59,12 @@
data => { 'action' => 'remove', 'hostname' => h.name, backend => h.peer_key, CSRFtoken => get_user_token(c), },
button => { class => 'iconOnly', title => "Remove this host with all services.", onclick => "return(confirm('really remove host?'))", html => '<i class="uil uil-trash-alt"></i>' },
}%]
[% IF info.exists(hostname) && info.$hostname.exists("inv_state") && info.$hostname.inv_state != 0 %]
<a href="agents.cgi?action=edit&amp;hostname=[% h.name | uri %]&backend=[% h.peer_key | html %]">
<i class="fa-solid fa-exclamation round small [% IF info.$hostname.inv_state == 1 %]yellow[% ELSE %]orange[% END %]" title="[% info.$hostname.inv_out | html %]"></i>
</a>
[% info.$hostname.inv_state %]
[% END %]
</div>
</td>
</tr>
Expand Down

0 comments on commit 76bcbc5

Please sign in to comment.