Local check with metrics

Hi,

I have a local check, it is a simple bash script which checks a VPN connection by making an API request, if the state is up, then the check_mk state is 1, otherwise it should go to critical. here is the script:

#!/bin/bash

SERVICE="vpn_state"
URL="https://api/jobs/jobid"

RESULT=$(curl -X GET -H 'X-Key: api-key' $URL)
STATS=$(echo $RESULT | jq '.status.global.status')
TIME=$(echo $RESULT | jq '.status.global.since')
DATE=$(date -d @$TIME)

echo "P ${SERVICE} state=1;;0 vpn is ${STATS} since ${DATE}"

this gives me critical always even if the status is up. any ideas?

Thanks
Ghassan

State is not a metric.

You should return the state in the first element of the local check output line. Instead of P just output 0 for OK or 2 for CRIT.

1 Like

Beside the answer from @r.sander the writing for minimal thresholds must look different.
Something like this

state=1;0:2;0:2

1 Like

Hi robert,

do you mean something like this:

if [ ${STATS} == '"up"' ]
then
    echo "0 ${SERVICE} state=1;;0 vpn is ${STATS} since ${DATE}"
else
    echo "2 ${SERVICE} - vpn is down"
fi

See the documentation.

The snippet state=1;;0 means:

  • the name of the metric is state
  • its current value is 1
  • the warn_upper threshold is undefined
  • the crit_upper threshold is 0

The automatic calculation (due to the P) is done as follows:

  • if the current value is greater than or equal to warn_upper, then go WARN. This doesn’t apply because warn_upper is undefined.
  • if the current value is greater than or equal to crit_upper, then go CRIT. This applies because 1>=0.
3 Likes

Well, that explains things. I just followed Robert’s suggestion and replaced P with the 0 and 2.

1 Like

In your case i think it is the best solution. As you have no real performance data :wink:

1 Like

Hi Andreas,

I am not interesting on a warning state, just either there is a connection or not, that is why I left the warning metric undefined, what I understand from you example that the graph will be from 0 to 2, one is up, 0 is warning and 2 is critical. Please correct me if I am wrong.
I wanted to connect the graph with the state, some thing like the attached imageScreenshot from 2020-06-15 08-54-48

I just used this simple if statement

To clarify my example

This is interpreted as @Dirk described
the value is 1
the first two numbers are the warning from - to → warning if 0 or lower and warning if 2 or higher
the second two numbers are critical from - to → critical if 0 or lower and critical if 2 or higher

As warning and critical have the same value you will get no warning but instant critical.
I only write it this way that all values are filled and it is clear for myself that there is no warning and only critical.

1 Like

Thanks for the explanation, I’ll do more tests until I find the best way to implement it.

then it is possible to write it this way, because I just don’t need any values above 1:

state=1;0;0;0;0

No :slight_smile:
pay attention to the format
You wrote

In my example there are a colon between the 0 and 2.
If you only want to make a critical with lower values your can write state=1;0:;0:
But i think CMK has a problem with local checks and this special format. That is why i write a upper value. You can also use there a value not reached at all like 99999.
Your check will be critical for every value 0 or higher. With this writing.

got you, didn’t see the colon, now it makes sense. So basically either setting an upper value or leave it empty, so I understand it correctly, I should use either: state=1;;0 or state=1;0:;0:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.