diff --git a/zabbix_conf/pve.conf b/zabbix_conf/pve.conf index 01f8ccf..ac8c6e7 100644 --- a/zabbix_conf/pve.conf +++ b/zabbix_conf/pve.conf @@ -1,10 +1,10 @@ # Discover PVE items # $1 can be nodes, guests, storage or pools -UserParameter=pve.discovery[*],/usr/bin/sudo /var/lib/zabbix/bin/disco_pve_sudo --what=$1 +UserParameter=pve.discovery[*],/usr/bin/sudo /var/lib/zabbix/bin/disco_pve_sudo --what $1 # Type: Agent or Agent (active) # pve.check.all[type,id] # Where type is what to monitor (pool, storage, node, cluster, guest) # id is the id of the item to monitor. For a guest, it's his numerical ID, for a storage # a node or a pool, its name. For the cluster, there's no ID -UserParameter=pve.check.all[*],/usr/bin/sudo /var/lib/zabbix/bin/check_pve_sudo --$1=$2 +UserParameter=pve.check.all[*],/usr/bin/sudo /var/lib/zabbix/bin/check_pve_sudo --$1 $2 diff --git a/zabbix_scripts/check_pve_sudo b/zabbix_scripts/check_pve_sudo index 59d3d07..b930110 100644 --- a/zabbix_scripts/check_pve_sudo +++ b/zabbix_scripts/check_pve_sudo @@ -37,7 +37,7 @@ if ($cluster){ my $guests = from_json(qx($pvesh get /cluster/resources --type=vm 2>/dev/null)); foreach my $g (@{$guests}){ if ($g->{vmid} eq $guest){ - $json = from_json(qx($pvesh get /nodes/$g->{node}/$g->{type}/$guest/status/current 2>/dev/null)); + $json = $g; last; } } @@ -57,6 +57,21 @@ if ($cluster){ $json->{templates}->{$item->{type}}++; } } + $json->{guests}->{$_} //= 0 foreach (qw(cpu maxcpu diskread diskwrite maxdisk mem maxmem netin netout)); + $json->{templates}->{$_} //= 0 foreach (qw(maxdisk)); +} elsif ($storage){ + $json = from_json(qx($pvesh get /storage/$storage 2>/dev/null)); + my $stores = from_json(qx($pvesh get /cluster/resources --type=storage 2>/dev/null)); + foreach my $s (@{$stores}){ + if ($s->{storage} eq $storage){ + $json->{maxdisk} = $s->{maxdisk}; + $json->{disk} = $s->{disk}; + last; + } + } +} else{ + print 'ZBX_UNSUPORTED'; + exit 0; } print to_json($json, { pretty => $pretty }) . "\n";