Skip to content

Instantly share code, notes, and snippets.

@metabsd
Created March 7, 2018 19:53
Show Gist options
  • Save metabsd/ba83bf0f54a50398c0996eb02b52c750 to your computer and use it in GitHub Desktop.
Save metabsd/ba83bf0f54a50398c0996eb02b52c750 to your computer and use it in GitHub Desktop.
Need help with Ansible and conditionnal from uri module.
Ansible JMESPATH / JSON Explorer
nagios_xi_services.json.servicelist.service[?service_description=='Service Status: Filebeat'].host_name
I want to run a task when the result is empty only.
Example of data I register by module uri in nagios_xi_services
{
"nagios_xi_services": {
"access_control_allow_methods": "*",
"access_control_allow_orgin": "*",
"changed": false,
"connection": "close",
"content": "{\"servicelist\":{\"recordcount\":\"15\",\"service\":[{\"@attributes\":{\"id\":\"3767\"},\"instance_id\":\"1\",\"host_name\":\"sldwbm0361\",\"service_description\":\"CPU Usage\",\"is_active\":\"1\",\"config_type\":\"1\",\"display_name\":\"CPU Usage\",\"check_interval\":\"15\",\"retry_interval\":\"1\",\"max_check_attempts\":\"10\",\"first_notification_delay\":\"120\",\"notification_interval\":\"60\",\"passive_checks_enabled\":\"1\",\"active_checks_enabled\":\"1\",\"notifications_enabled\":\"1\",\"notes\":\"\",\"notes_url\":\"\",\"action_url\":\"\",\"icon_image\":\"\",\"icon_image_alt\":\"\"},{\"@attributes\":{\"id\":\"3768\"},\"instance_id\":\"1\",\"host_name\":\"sldwbm0361\",\"service_description\":\"Memory Usage\",\"is_active\":\"1\",\"config_type\":\"1\",\"display_name\":\"Memory Usage\",\"check_interval\":\"5\",\"retry_interval\":\"1\",\"max_check_attempts\":\"5\",\"first_notification_delay\":\"0\",\"notification_interval\":\"60\",\"passive_checks_enabled\":\"1\",\"active_checks_enabled\":\"1\",\"notifications_enabled\":\"1\",\"notes\":\"\",\"notes_url\":\"\",\"action_url\":\"\",\"icon_image\":\"\",\"icon_image_alt\":\"\"},{\"@attributes\":{\"id\":\"3770\"},\"instance_id\":\"1\",\"host_name\":\"sldwbm0361\",\"service_description\":\"Swap Usage\",\"is_active\":\"1\",\"config_type\":\"1\",\"display_name\":\"Swap Usage\",\"check_interval\":\"5\",\"retry_interval\":\"1\",\"max_check_attempts\":\"5\",\"first_notification_delay\":\"0\",\"notification_interval\":\"60\",\"passive_checks_enabled\":\"1\",\"active_checks_enabled\":\"1\",\"notifications_enabled\":\"1\",\"notes\":\"\",\"notes_url\":\"\",\"action_url\":\"\",\"icon_image\":\"\",\"icon_image_alt\":\"\"},{\"@attributes\":{\"id\":\"3773\"},\"instance_id\":\"1\",\"host_name\":\"sldwbm0361\",\"service_description\":\"Disk Usage on \\/opt\",\"is_active\":\"1\",\"config_type\":\"1\",\"display_name\":\"Disk Usage on \\/opt\",\"check_interval\":\"5\",\"retry_interval\":\"1\",\"max_check_attempts\":\"5\",\"first_notification_delay\":\"0\",\"notification_interval\":\"60\",\"passive_checks_enabled\":\"1\",\"active_checks_enabled\":\"1\",\"notifications_enabled\":\"1\",\"notes\":\"\",\"notes_url\":\"\",\"action_url\":\"\",\"icon_image\":\"\",\"icon_image_alt\":\"\"},{\"@attributes\":{\"id\":\"3774\"},\"instance_id\":\"1\",\"host_name\":\"sldwbm0361\",\"service_description\":\"Disk Usage on \\/var\",\"is_active\":\"1\",\"config_type\":\"1\",\"display_name\":\"Disk Usage on \\/var\",\"check_interval\":\"5\",\"retry_interval\":\"1\",\"max_check_attempts\":\"5\",\"first_notification_delay\":\"0\",\"notification_interval\":\"60\",\"passive_checks_enabled\":\"1\",\"active_checks_enabled\":\"1\",\"notifications_enabled\":\"1\",\"notes\":\"\",\"notes_url\":\"\",\"action_url\":\"\",\"icon_image\":\"\",\"icon_image_alt\":\"\"},{\"@attributes\":{\"id\":\"3775\"},\"instance_id\":\"1\",\"host_name\":\"sldwbm0361\",\"service_description\":\"Disk Usage on \\/usr\",\"is_active\":\"1\",\"config_type\":\"1\",\"display_name\":\"Disk Usage on \\/usr\",\"check_interval\":\"5\",\"retry_interval\":\"1\",\"max_check_attempts\":\"5\",\"first_notification_delay\":\"0\",\"notification_interval\":\"60\",\"passive_checks_enabled\":\"1\",\"active_checks_enabled\":\"1\",\"notifications_enabled\":\"1\",\"notes\":\"\",\"notes_url\":\"\",\"action_url\":\"\",\"icon_image\":\"\",\"icon_image_alt\":\"\"},{\"@attributes\":{\"id\":\"3776\"},\"instance_id\":\"1\",\"host_name\":\"sldwbm0361\",\"service_description\":\"Disk Usage on \\/boot\",\"is_active\":\"1\",\"config_type\":\"1\",\"display_name\":\"Disk Usage on \\/boot\",\"check_interval\":\"5\",\"retry_interval\":\"1\",\"max_check_attempts\":\"5\",\"first_notification_delay\":\"0\",\"notification_interval\":\"60\",\"passive_checks_enabled\":\"1\",\"active_checks_enabled\":\"1\",\"notifications_enabled\":\"1\",\"notes\":\"\",\"notes_url\":\"\",\"action_url\":\"\",\"icon_image\":\"\",\"icon_image_alt\":\"\"},{\"@attributes\":{\"id\":\"3777\"},\"instance_id\":\"1\",\"host_name\":\"sldwbm0361\",\"service_description\":\"Disk Usage on \\/\",\"is_active\":\"1\",\"config_type\":\"1\",\"display_name\":\"Disk Usage on \\/\",\"check_interval\":\"5\",\"retry_interval\":\"1\",\"max_check_attempts\":\"5\",\"first_notification_delay\":\"0\",\"notification_interval\":\"60\",\"passive_checks_enabled\":\"1\",\"active_checks_enabled\":\"1\",\"notifications_enabled\":\"1\",\"notes\":\"\",\"notes_url\":\"\",\"action_url\":\"\",\"icon_image\":\"\",\"icon_image_alt\":\"\"},{\"@attributes\":{\"id\":\"3778\"},\"instance_id\":\"1\",\"host_name\":\"sldwbm0361\",\"service_description\":\"Disk Usage on \\/tmp\",\"is_active\":\"1\",\"config_type\":\"1\",\"display_name\":\"Disk Usage on \\/tmp\",\"check_interval\":\"5\",\"retry_interval\":\"1\",\"max_check_attempts\":\"5\",\"first_notification_delay\":\"0\",\"notification_interval\":\"60\",\"passive_checks_enabled\":\"1\",\"active_checks_enabled\":\"1\",\"notifications_enabled\":\"1\",\"notes\":\"\",\"notes_url\":\"\",\"action_url\":\"\",\"icon_image\":\"\",\"icon_image_alt\":\"\"},{\"@attributes\":{\"id\":\"3779\"},\"instance_id\":\"1\",\"host_name\":\"sldwbm0361\",\"service_description\":\"Disk Usage on \\/home\",\"is_active\":\"1\",\"config_type\":\"1\",\"display_name\":\"Disk Usage on \\/home\",\"check_interval\":\"5\",\"retry_interval\":\"1\",\"max_check_attempts\":\"5\",\"first_notification_delay\":\"0\",\"notification_interval\":\"60\",\"passive_checks_enabled\":\"1\",\"active_checks_enabled\":\"1\",\"notifications_enabled\":\"1\",\"notes\":\"\",\"notes_url\":\"\",\"action_url\":\"\",\"icon_image\":\"\",\"icon_image_alt\":\"\"},{\"@attributes\":{\"id\":\"3780\"},\"instance_id\":\"1\",\"host_name\":\"sldwbm0361\",\"service_description\":\"Disk Usage on \\/opt\\/webMethods9\",\"is_active\":\"1\",\"config_type\":\"1\",\"display_name\":\"Disk Usage on \\/opt\\/webMethods9\",\"check_interval\":\"5\",\"retry_interval\":\"1\",\"max_check_attempts\":\"5\",\"first_notification_delay\":\"0\",\"notification_interval\":\"60\",\"passive_checks_enabled\":\"1\",\"active_checks_enabled\":\"1\",\"notifications_enabled\":\"1\",\"notes\":\"\",\"notes_url\":\"\",\"action_url\":\"\",\"icon_image\":\"\",\"icon_image_alt\":\"\"},{\"@attributes\":{\"id\":\"3781\"},\"instance_id\":\"1\",\"host_name\":\"sldwbm0361\",\"service_description\":\"eth0 Bandwidth - Inbound\",\"is_active\":\"1\",\"config_type\":\"1\",\"display_name\":\"eth0 Bandwidth - Inbound\",\"check_interval\":\"5\",\"retry_interval\":\"1\",\"max_check_attempts\":\"5\",\"first_notification_delay\":\"0\",\"notification_interval\":\"60\",\"passive_checks_enabled\":\"1\",\"active_checks_enabled\":\"1\",\"notifications_enabled\":\"1\",\"notes\":\"\",\"notes_url\":\"\",\"action_url\":\"\",\"icon_image\":\"\",\"icon_image_alt\":\"\"},{\"@attributes\":{\"id\":\"3782\"},\"instance_id\":\"1\",\"host_name\":\"sldwbm0361\",\"service_description\":\"eth0 Bandwidth - Outbound\",\"is_active\":\"1\",\"config_type\":\"1\",\"display_name\":\"eth0 Bandwidth - Outbound\",\"check_interval\":\"5\",\"retry_interval\":\"1\",\"max_check_attempts\":\"5\",\"first_notification_delay\":\"0\",\"notification_interval\":\"60\",\"passive_checks_enabled\":\"1\",\"active_checks_enabled\":\"1\",\"notifications_enabled\":\"1\",\"notes\":\"\",\"notes_url\":\"\",\"action_url\":\"\",\"icon_image\":\"\",\"icon_image_alt\":\"\"},{\"@attributes\":{\"id\":\"11855\"},\"instance_id\":\"1\",\"host_name\":\"sldwbm0361\",\"service_description\":\"Service Status: Unix Services\",\"is_active\":\"1\",\"config_type\":\"1\",\"display_name\":\"Service Status: Unix Services\",\"check_interval\":\"5\",\"retry_interval\":\"1\",\"max_check_attempts\":\"5\",\"first_notification_delay\":\"0\",\"notification_interval\":\"60\",\"passive_checks_enabled\":\"1\",\"active_checks_enabled\":\"1\",\"notifications_enabled\":\"1\",\"notes\":\"\",\"notes_url\":\"\",\"action_url\":\"\",\"icon_image\":\"\",\"icon_image_alt\":\"\"},{\"@attributes\":{\"id\":\"24533\"},\"instance_id\":\"1\",\"host_name\":\"sldwbm0361\",\"service_description\":\"Service Status: Filebeat\",\"is_active\":\"1\",\"config_type\":\"1\",\"display_name\":\"Service Status: Filebeat\",\"check_interval\":\"5\",\"retry_interval\":\"1\",\"max_check_attempts\":\"5\",\"first_notification_delay\":\"0\",\"notification_interval\":\"60\",\"passive_checks_enabled\":\"1\",\"active_checks_enabled\":\"1\",\"notifications_enabled\":\"1\",\"notes\":\"\",\"notes_url\":\"\",\"action_url\":\"\",\"icon_image\":\"\",\"icon_image_alt\":\"\"}]}}\n",
"content_length": "7249",
"content_type": "application/json",
"cookies": {},
"date": "Wed, 07 Mar 2018 04:50:43 GMT",
"failed": false,
"json": {
"servicelist": {
"recordcount": "15",
"service": [
{
"@attributes": {
"id": "3767"
},
"action_url": "",
"active_checks_enabled": "1",
"check_interval": "15",
"config_type": "1",
"display_name": "CPU Usage",
"first_notification_delay": "120",
"host_name": "sldwbm0361",
"icon_image": "",
"icon_image_alt": "",
"instance_id": "1",
"is_active": "1",
"max_check_attempts": "10",
"notes": "",
"notes_url": "",
"notification_interval": "60",
"notifications_enabled": "1",
"passive_checks_enabled": "1",
"retry_interval": "1",
"service_description": "CPU Usage"
},
{
"@attributes": {
"id": "3768"
},
"action_url": "",
"active_checks_enabled": "1",
"check_interval": "5",
"config_type": "1",
"display_name": "Memory Usage",
"first_notification_delay": "0",
"host_name": "sldwbm0361",
"icon_image": "",
"icon_image_alt": "",
"instance_id": "1",
"is_active": "1",
"max_check_attempts": "5",
"notes": "",
"notes_url": "",
"notification_interval": "60",
"notifications_enabled": "1",
"passive_checks_enabled": "1",
"retry_interval": "1",
"service_description": "Memory Usage"
},
{
"@attributes": {
"id": "3770"
},
"action_url": "",
"active_checks_enabled": "1",
"check_interval": "5",
"config_type": "1",
"display_name": "Swap Usage",
"first_notification_delay": "0",
"host_name": "sldwbm0361",
"icon_image": "",
"icon_image_alt": "",
"instance_id": "1",
"is_active": "1",
"max_check_attempts": "5",
"notes": "",
"notes_url": "",
"notification_interval": "60",
"notifications_enabled": "1",
"passive_checks_enabled": "1",
"retry_interval": "1",
"service_description": "Swap Usage"
},
{
"@attributes": {
"id": "3773"
},
"action_url": "",
"active_checks_enabled": "1",
"check_interval": "5",
"config_type": "1",
"display_name": "Disk Usage on /opt",
"first_notification_delay": "0",
"host_name": "sldwbm0361",
"icon_image": "",
"icon_image_alt": "",
"instance_id": "1",
"is_active": "1",
"max_check_attempts": "5",
"notes": "",
"notes_url": "",
"notification_interval": "60",
"notifications_enabled": "1",
"passive_checks_enabled": "1",
"retry_interval": "1",
"service_description": "Disk Usage on /opt"
},
{
"@attributes": {
"id": "3774"
},
"action_url": "",
"active_checks_enabled": "1",
"check_interval": "5",
"config_type": "1",
"display_name": "Disk Usage on /var",
"first_notification_delay": "0",
"host_name": "sldwbm0361",
"icon_image": "",
"icon_image_alt": "",
"instance_id": "1",
"is_active": "1",
"max_check_attempts": "5",
"notes": "",
"notes_url": "",
"notification_interval": "60",
"notifications_enabled": "1",
"passive_checks_enabled": "1",
"retry_interval": "1",
"service_description": "Disk Usage on /var"
},
{
"@attributes": {
"id": "3775"
},
"action_url": "",
"active_checks_enabled": "1",
"check_interval": "5",
"config_type": "1",
"display_name": "Disk Usage on /usr",
"first_notification_delay": "0",
"host_name": "sldwbm0361",
"icon_image": "",
"icon_image_alt": "",
"instance_id": "1",
"is_active": "1",
"max_check_attempts": "5",
"notes": "",
"notes_url": "",
"notification_interval": "60",
"notifications_enabled": "1",
"passive_checks_enabled": "1",
"retry_interval": "1",
"service_description": "Disk Usage on /usr"
},
{
"@attributes": {
"id": "3776"
},
"action_url": "",
"active_checks_enabled": "1",
"check_interval": "5",
"config_type": "1",
"display_name": "Disk Usage on /boot",
"first_notification_delay": "0",
"host_name": "sldwbm0361",
"icon_image": "",
"icon_image_alt": "",
"instance_id": "1",
"is_active": "1",
"max_check_attempts": "5",
"notes": "",
"notes_url": "",
"notification_interval": "60",
"notifications_enabled": "1",
"passive_checks_enabled": "1",
"retry_interval": "1",
"service_description": "Disk Usage on /boot"
},
{
"@attributes": {
"id": "3777"
},
"action_url": "",
"active_checks_enabled": "1",
"check_interval": "5",
"config_type": "1",
"display_name": "Disk Usage on /",
"first_notification_delay": "0",
"host_name": "sldwbm0361",
"icon_image": "",
"icon_image_alt": "",
"instance_id": "1",
"is_active": "1",
"max_check_attempts": "5",
"notes": "",
"notes_url": "",
"notification_interval": "60",
"notifications_enabled": "1",
"passive_checks_enabled": "1",
"retry_interval": "1",
"service_description": "Disk Usage on /"
},
{
"@attributes": {
"id": "3778"
},
"action_url": "",
"active_checks_enabled": "1",
"check_interval": "5",
"config_type": "1",
"display_name": "Disk Usage on /tmp",
"first_notification_delay": "0",
"host_name": "sldwbm0361",
"icon_image": "",
"icon_image_alt": "",
"instance_id": "1",
"is_active": "1",
"max_check_attempts": "5",
"notes": "",
"notes_url": "",
"notification_interval": "60",
"notifications_enabled": "1",
"passive_checks_enabled": "1",
"retry_interval": "1",
"service_description": "Disk Usage on /tmp"
},
{
"@attributes": {
"id": "3779"
},
"action_url": "",
"active_checks_enabled": "1",
"check_interval": "5",
"config_type": "1",
"display_name": "Disk Usage on /home",
"first_notification_delay": "0",
"host_name": "sldwbm0361",
"icon_image": "",
"icon_image_alt": "",
"instance_id": "1",
"is_active": "1",
"max_check_attempts": "5",
"notes": "",
"notes_url": "",
"notification_interval": "60",
"notifications_enabled": "1",
"passive_checks_enabled": "1",
"retry_interval": "1",
"service_description": "Disk Usage on /home"
},
{
"@attributes": {
"id": "3780"
},
"action_url": "",
"active_checks_enabled": "1",
"check_interval": "5",
"config_type": "1",
"display_name": "Disk Usage on /opt/webMethods9",
"first_notification_delay": "0",
"host_name": "sldwbm0361",
"icon_image": "",
"icon_image_alt": "",
"instance_id": "1",
"is_active": "1",
"max_check_attempts": "5",
"notes": "",
"notes_url": "",
"notification_interval": "60",
"notifications_enabled": "1",
"passive_checks_enabled": "1",
"retry_interval": "1",
"service_description": "Disk Usage on /opt/webMethods9"
},
{
"@attributes": {
"id": "3781"
},
"action_url": "",
"active_checks_enabled": "1",
"check_interval": "5",
"config_type": "1",
"display_name": "eth0 Bandwidth - Inbound",
"first_notification_delay": "0",
"host_name": "sldwbm0361",
"icon_image": "",
"icon_image_alt": "",
"instance_id": "1",
"is_active": "1",
"max_check_attempts": "5",
"notes": "",
"notes_url": "",
"notification_interval": "60",
"notifications_enabled": "1",
"passive_checks_enabled": "1",
"retry_interval": "1",
"service_description": "eth0 Bandwidth - Inbound"
},
{
"@attributes": {
"id": "3782"
},
"action_url": "",
"active_checks_enabled": "1",
"check_interval": "5",
"config_type": "1",
"display_name": "eth0 Bandwidth - Outbound",
"first_notification_delay": "0",
"host_name": "sldwbm0361",
"icon_image": "",
"icon_image_alt": "",
"instance_id": "1",
"is_active": "1",
"max_check_attempts": "5",
"notes": "",
"notes_url": "",
"notification_interval": "60",
"notifications_enabled": "1",
"passive_checks_enabled": "1",
"retry_interval": "1",
"service_description": "eth0 Bandwidth - Outbound"
},
{
"@attributes": {
"id": "11855"
},
"action_url": "",
"active_checks_enabled": "1",
"check_interval": "5",
"config_type": "1",
"display_name": "Service Status: Unix Services",
"first_notification_delay": "0",
"host_name": "sldwbm0361",
"icon_image": "",
"icon_image_alt": "",
"instance_id": "1",
"is_active": "1",
"max_check_attempts": "5",
"notes": "",
"notes_url": "",
"notification_interval": "60",
"notifications_enabled": "1",
"passive_checks_enabled": "1",
"retry_interval": "1",
"service_description": "Service Status: Unix Services"
},
{
"@attributes": {
"id": "24533"
},
"action_url": "",
"active_checks_enabled": "1",
"check_interval": "5",
"config_type": "1",
"display_name": "Service Status: Filebeat",
"first_notification_delay": "0",
"host_name": "sldwbm0361",
"icon_image": "",
"icon_image_alt": "",
"instance_id": "1",
"is_active": "1",
"max_check_attempts": "5",
"notes": "",
"notes_url": "",
"notification_interval": "60",
"notifications_enabled": "1",
"passive_checks_enabled": "1",
"retry_interval": "1",
"service_description": "Service Status: Filebeat"
}
]
}
},
"msg": "OK (7249 bytes)",
"redirected": false,
"server": "Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/5.4.16",
"status": 200,
"url": "https://nagiosxi/nagiosxi/api/v1/objects/service?apikey=APIKEY&host_name=in:sldwbm0361",
"x_powered_by": "PHP/5.4.16"
}
}
RESULT :::
[
"sldwbm0361"
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment