Skip to content

select/limit output? #106

@chri2

Description

@chri2

I'm using nagios-http-json to monitor netdata. My problem is that I didn't find an elegant way to limit or select the output returned by check_http_json.py:

root@packetfence3:~# /usr/local/lib/nagios-http-json/check_http_json.py -H 127.0.0.1 -P 19999 -p 'api/v1/alarms' -Q 'alarms','{}'
CRITICAL: Status CRITICAL. Key alarms mismatch. {} != {'haproxy_haproxy-portal.health_sdown.haproxy_backend_server_status': {'id': 1741607668, 'config_hash_id': '3a7975f3-dfd3-4e71-b54d-e3342ab7c808', 'name': 'haproxy_backend_server_status', 'chart': 'haproxy_haproxy-portal.health_sdown', 'class': 'Errors', 'component': 'HAProxy', 'type': 'Web Proxy', 'active': True, 'disabled': False, 'silenced': False, 'exec': '/usr/libexec/netdata/plugins.d/alarm-notify.sh', 'recipient': 'sysadmin', 'source': 'line=4,file=/etc/netdata/health.d/haproxy.conf', 'units': 'failed servers', 'summary': 'HAProxy server status', 'info': 'Average number of failed haproxy backend servers over the last 10 seconds', 'status': 'CRITICAL', 'last_status_change': 1764155510, 'last_updated': 1764229321, 'next_update': 1764229331, 'update_every': 10, 'delay_up_duration': 0, 'delay_down_duration': 0, 'delay_max_duration': 0, 'delay_multiplier': 1.0, 'delay': 0, 'delay_up_to_timestamp': 1764155510, 'warn_repeat_every': '0', 'crit_repeat_every': '0', 'value_string': '2 failed servers', 'last_repeat': '0', 'times_repeat': 0, 'db_after': 1764229311, 'db_before': 1764229320, 'lookup_method': 'average', 'lookup_after': -10, 'lookup_before': 0, 'lookup_options': '', 'crit': '$this > 0', 'crit_parsed': '(${this} > 0)', 'green': None, 'red': None, 'value': 2}}

This is very hard to read. I tried to find a way to to get something like this…

"haproxy_backend_server_status"
"haproxy_haproxy-portal.health_sdown"
"2 failed servers"

…which contains the important information only and leaves out all the technical netdata information.

I ended up with this command:

/usr/local/lib/nagios-http-json/check_http_json.py -H 127.0.0.1 -P 19999 -p 'api/v1/alarms' -Q 'alarms','{}' \
| cut -d'=' -f2- \
| perl -pe"s/'/\"/g; s/True/true/g; s/False/false/g; s/None/\"None\"/g" \
| jq '.[].name,.[].chart,.[].value_string,.[].value'

I have two question:

  • Did I overlook some option that could filter out the returned json attributes?
  • Why is the returned json not valid for jq? Did I miss some option to jq?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions