diff --git a/check_pve.rb b/check_pve.rb index b980b5a..9ec3679 100755 --- a/check_pve.rb +++ b/check_pve.rb @@ -355,6 +355,21 @@ class CheckPve check_thresholds(data: value) end + # helper for nested percentage values + def node_helper_to_nested_pct(path: 'status', key:, value:, output_msg:, perf_label: 'Usage', **args) + http_connect(path: "api2/json/nodes/#{@options[:node]}/#{path}") + data = JSON.parse(@response.body)['data'][key] + # calc used data + value = if args.empty? + format_float(float_data: data[value]) + else + format_float(float_data: data[value].to_f / data[args[:value_to_compare]]) + end + build_output(msg: "#{output_msg}: #{value}%") + build_perfdata(perfdata: "#{perf_label}=#{value}%") + check_thresholds(data: value) + end + # helper for unit values def node_helper_to_units(path: 'status', type:, value: 'used', output_msg:, unit: 'gb', perf_label: 'Usage') http_connect(path: "api2/json/nodes/#{@options[:node]}/#{path}") @@ -395,7 +410,12 @@ class CheckPve ### node: memory def mem return unless @options[:mode] == 'memory' - node_helper_to_units(type: 'memory', output_msg: 'Memory Usage') + node_helper_to_nested_pct( + key: 'memory', + value: 'used', + value_to_compare: 'total', + output_msg: 'Memory usage' + ) end ### node: ksm