REST-API - get IP address

Good day Everyone.
I would like to ask if anybody can help with one problem. I use rest-api curl from documentation to get all host which are down but the reply from get only contains hostnames but I would want also to get IP addresses. Is there any option to add ip address to extension or some other?

Your help would be appreciated.

Curl:
#!/bin/bash

# NOTE: We recommend all shell users to use the “httpie” examples instead.

HOST_NAME=“localhost”
SITE_NAME=“mysite”
API_URL=“http://$HOST_NAME/$SITE_NAME/check_mk/api/1.0”

USERNAME=“automation”
PASSWORD=“test123”

out=$(

  • curl *
  • -G *
  • –request GET *
  • –write-out “\nxxx-status_code=%{http_code}\n” *
  • –header “Authorization: Bearer $USERNAME $PASSWORD” *
  • –header “Accept: application/json” *
  • –data-urlencode ‘query={“op”: “!=”, “left”: “state”, “right”: “0”}’ *
  • “$API_URL/domain-types/host/collections/all”)*

resp=$( echo “${out}” | grep -v “xxx-status_code” )
code=$( echo “${out}” | awk -F"=" ‘/^xxx-status_code/ {print $2}’)

# For indentation, please install ‘jq’ (JSON query tool)
echo “$resp” | jq
# echo “$resp”

if [[ $code -lt 400 ]]; then

  • echo “OK”*
  • exit 0*
    else
  • echo “Request error”*
  • exit 1*
    fi

Hi,

you can add the parameter “effective_attributes=1” in your call. With this parameter you get all set attributes to an agent. If you set IP Adress in WATO you will also see it.

Cheers,
Christian

Hi,
thank you for your answer. I tried to add effective_attribute to my script but my attempts were unsuccessful. It is my first time to work with check_mk api and curl so if you would be so kind and write me some example how to add this parameter correctly to script. I would be very grateful

Good day

Hi,

try this:

“$API_URL/domain-types/host/collections/all?effective_attributes=true”)*```

Hi,

i get this error when running script after using that line of code.

{
“title”: “Bad Request”,
“status”: 400,
“detail”: “These fields have problems: effective_attributes”,
“fields”: {
“effective_attributes”: [
“Unknown field.”
]
}
}
Request error

I have found a way using livestatus-query but thank you for your help.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.