Skip to content

Commit

Permalink
agents: list os version and arch
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Jan 10, 2024
1 parent da83b0e commit af3833d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
21 changes: 20 additions & 1 deletion plugins/plugins-available/agents/lib/Thruk/Controller/agents.pm
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ sub _process_show {

my $services = $c->db->get_services(filter => [ Thruk::Utils::Auth::get_auth_filter( $c, 'hosts' ),
'host_custom_variables' => { '~' => 'AGENT .+' },
'description' => { '~' => '^(agent version|agent inventory|memory|cpu|disk.*)$' },
'description' => { '~' => '^(agent version|agent inventory|memory|cpu|disk.*|os version)$' },
],
'extra_columns' => [qw/long_plugin_output/],
);
Expand Down Expand Up @@ -131,6 +131,9 @@ sub _process_show {
'disk_state' => 0,
'disk_total' => '',
'disk_free' => '',
'os_version_full' => '',
'os_version' => '',
'os_arch' => '',
};
if($svc->{'description'} eq 'agent version') {
if($svc->{'state'} == 0) {
Expand Down Expand Up @@ -188,6 +191,22 @@ sub _process_show {
}
}
}
if($svc->{'description'} eq 'os version') {
if($svc->{'plugin_output'} =~ m/\(arch:(.*?)\)/mx) {
my $arch = Thruk::Base::trim_whitespace("$1");
$arch = "x86" if $arch eq "amd64";
$arch = "aarch64" if $arch eq "arm64";
$extra->{'os_arch'} = $arch;
}
$extra->{'os_version_full'} = $svc->{'plugin_output'};
$extra->{'os_version_full'} =~ s/^\w+\ \- \ //gmx;
$extra->{'os_version'} = lc($svc->{'plugin_output'});
$extra->{'os_version'} =~ s/^\w+\ \- \ //gmx;
$extra->{'os_version'} =~ s/^microsoft\ //gmx;
$extra->{'os_version'} =~ s/\ build\ [\d.]+\ / /gmx;
$extra->{'os_version'} =~ s/\(arch:[^)]*\)+/ /gmx;
$extra->{'os_version'} =~ s/^darwin\ /mac osx /gmx;
}
$info->{$svc->{'host_name'}} = $extra;
}
$c->stash->{info} = $info;
Expand Down
19 changes: 13 additions & 6 deletions plugins/plugins-available/agents/templates/agents.tt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
<th class="">Hostname</th>
<th class="w-20 text-center">Status</th>
<th class="w-20">Site</th>
<th class="w-24">Agent</th>
<th class="w-20">Version</th>
<th class="w-24">Version</th>
<th class="w-24">OS</th>
<th class="w-10">Arch</th>
<th class="w-24">CPU</th>
<th class="w-24">Memory</th>
<th class="w-24">Disk</th>
Expand Down Expand Up @@ -69,10 +70,16 @@
<div class='text-center badge [% state %]'[% IF output != "" %] title="[% output | html %]"[% END %]>[% 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 info.exists(hostname) %]<div class="w-full h-full" title="[% info.$hostname.full_version | html %]">[% info.$hostname.version | html %]</div>[% END %]</td>


<td>
<div class="flexrow flex-nowrap gap-x-1">
<div class="w-5 h-5 m-0 p-0 min-w-fit"><img src="[% url_prefix %]plugins/[% plugin_name %]/images/[% agent.icon | html %]" alt="[% agent.type | html %]" width=25 height=25></div>
[% IF info.exists(hostname) %]<div class="w-full h-full" title="[% info.$hostname.full_version | html %]">[% info.$hostname.version | html %]</div>[% END %]
</div>
</td>
<td>
<span title="[% info.$hostname.os_version_full %]">[% info.$hostname.os_version %]</span>
</td>
<td>[% info.$hostname.os_arch %]</td>
<td class='align-top relative'>
[% IF info.$hostname.cpu_perc; %][%IF info.$hostname.cpu_perc > 1; info.$hostname.cpu_perc = 1; END %]
<div style='width: [% 100 * info.$hostname.cpu_perc %]%; height: 100%;' class='[% IF info.$hostname.cpu_state == 2 %]CRITICAL[% ELSIF info.$hostname.cpu_state == 1 %]WARNING[% ELSE %]OK[% END %] absolute top-0 left-0' title="cpu usage: [% 100 * info.$hostname.cpu_perc %]%"></div>
Expand Down

0 comments on commit af3833d

Please sign in to comment.