CMK version: Raw Edition: 2.2.0p27
OS version: AZ Linux
Error message: During service discovery I get “UNKNOWN - Database names not provided”
I’m trying to inject a variable (mongo_db_name) from a custom host attribute (WATO → Custom Host Attribute) into a check script.
I’ve got the attribute data type set to Simple Text and assigned to a host. In my script I’m trying to reference the variable by:
if [ -n "$1" ]; then
db_names="$1"
else
db_names="${mongo_db_name}"
fi
but it seems like this variable is not being passed from the host config to my script. Has anyone had success doing this? Is my approach way off base?
r.sander
(Robert Sander)
July 23, 2024, 4:57am
2
Is your script a Nagios plugin that runs as active check on the monitoring server?
There is some documentation missing on how to actually use them in check commands, @mschlenker .
E.g. how is the macro called for a custom host attribute and how to use it with active checks and notifications.
Yes, its runs as an active check on the monitoring server.
Also, this is a custom script, not a nagios plugin.
Hi - just reaching out to see if there’s been any updates on this?
If you want to use custom host/service attributes as macros in your Nagios checks then you can use the following syntax:
Custom Host attributes: $HOST_[attr_id_in_capitals]$
Custom Service attributes: $SERVICE_[attr_id_in_capitals]$
Hi - thanks for the info! I still must be doing something incorrectly, though. I’m trying to use this:
# Determine the database names
if [ -n "$1" ]; then
db_name="$1"
else
db_name="$HOST_[MONGO_DB_NAME]$"
fi
This is how I have the custom attribute defined in CMK. (assigned to the host)
When I run the agent it looks like the variable isnt being passed to my script:
Executing MongoDB size check for database: $
Result: UNKNOWN - Error: database names cannot contain the character '$'
3 DataBase.$.Size UNKNOWN UNKNOWN - Error: database names cannot contain the character '$
Have you already selected the following like in the screenshot?
Anders
(Anders)
August 26, 2024, 5:12pm
10
active checks will not have access to host attributes unless I have missed something.
you will have access to nagios variables however.
this is at least how we have done our active checks using the nagios macros file
mimimi
(Y0d0g)
August 28, 2024, 9:45am
11
You could lookup information from livestatus in your nagios compatible check.
checkmk runs your nagios script with $HOSTNAME$ as parameter
Your nagios script then does a lq query with the help of $1 on the running checkmk instance to get whatever you need.