Localcheck input counter - calculate difference from previous check result

I am currently in the process of developing a Localcheck.
One of the results is a counter, which will increment over time, producing a steady inceasing line in a/the graph.

The thing is, that i am not interested in the counter by itself, but rather the difference of the counter compare to the previously received result.

As this involves comparing looking at the result of a previous poll to the last pull (IMHO) this should/would be handled by the CMK server itself (as that has/retains the data of a/the previous pull)

I have been digging thru docs and forum to find if this is possible, but either i am overlooking it, or its not there.

So general questions are:

  • Is there such a function/possibility implemented ?
  • if so any examples ?
  • if not, any alternatives as to achieving my goal ? → do take in mind that it is my goal to convert this check into a special agent.

Hope to hear back/ your input on this matter.

  • Glowsome

If you go the way to the special agent (or agent plugin) you can use get_rate() in the check plugin.

It is available in the check API v1 and v2.

1 Like

Hi,

good to know that there is a way when i go for a/the special agent, but until then, is it possible for a localcheck( still far away from going from a localcheck to a special agent)?

  • Glowsome

Currently, this is not possible.

I have filed a proposal for an extension of the local check plugin to handle counter values to the Checkmk feedback address some years ago, but it was not considered.

Edit: this was FEED-3636 from May 26 2019 in the tribe29 Jira issue tracker.

No, for local checks currently no such function exists. Maybe because it’s trivial to write one or because local checks can be written in any language, e.g. bash, python, or even C++, and they didn’t know what language to use.

In bash a simple function might look like this:

#!/usr/bin/env bash

get_delta() {
    current_value=$1
    counter_file=/var/tmp/mycounter.txt

    # read old value from file or default to "0" if that fails:
    old_value=$(cat $counter_file 2>/dev/null || echo 0);

    # store new value:
    echo $current_value > $counter_file;

    # return the delta:
    echo $(( current_value - old_value ))
}

################

new_value=5;
delta=$( get_delta $new_value )
echo "The delta is $delta"
1 Like

All of the above, but especially the last part. :slight_smile:

1 Like