Help to create a custom plug-in

Hello,
I am learning Python to be able to develop custom plugins, I have several powershell and bash scripts to be able to monitor various things in our environment, and that’s where all this comes from.
I have created a very very simple sh that gives me the following information,
imagen


I created the python file as follows,

I think the parse function will be fine

The problem is that as a result I get nothing, neither plugin discovery nor any error in the debug.

Maybe I’m missing something because I’ve been thinking about it for a long time.
I would be very grateful for some help to be able to follow the way forward.

Somehow your agent data ends up in the local check plugin.
Are you sure that the section header is correct? It looks like it is missing the third >.

3 Likes

Hi Mario! As @r.sander said: it seems that you just forgot the third > in the section header. Correct is <<<customcheck:sep(32)>>>.

If the section header is wrong then checkmk doesn’t recognise the data as a new section and just adds the line <<<customcheck>> (with two >) to the data of the previous section (which apparantly was the <<<local>>> section) and that usually crashes because of unexpected input.


Allow me to give you some hints:

Hint #1: :sep(32) is a single blank character. If you omit the separator (as in <<<customcheck>>>) then checkmk will automatically split the input at (any amount of) whitespace (blank or tab). This is the default behaviour.

Hint #2 I like your parse function. But you could write the for loop a bit easier. Instead of iterating over the index (1…n) whithin the string_table:

# orginal code
def parse_customcheck(string_table):
    parsed = {}
    for line in range(len(string_table)):
        parsed[string_table[line][0]] = {
            "size": string_table[line][1],
            "used": string_table[line][2],
            "free": string_table[line][3]
        }
    return parsed

… you may directly iterate the string_table line by line:

def parse_customcheck(string_table):
    parsed = {}
    for line in string_table: 
        parsed[line[0]] = {
            "size": line[1],
            "used": line[2],
            "free": line[3]
        }
    return parsed

Because line itself is a list of strings you may also immediately assign it to individual variables while iterating. Like so:

def parse_customcheck(string_table):
    parsed = {}
    for name, size, used, free in string_table:
        parsed[name] = {
            "size": size,
            "used": used,
            "free": free
        }
    return parsed

But be aware that the number of variables (name, size, used, free) must now match the number of “items” in the line. So if you encounter a line with 3 or 5 items, this last code will crash. I think this code is easier to read.

2 Likes

oh god!!!
I must have run it countless times but never noticed it!
Thanx Robert.
I will continue researching to generate more plugins

1 Like

wow
thanks for the tips, they are really good for me to continue learning python coding, I’ve been working with the … for a really short time, I’ve played a lot more powershell and that’s why I decided to learn python along with the possibilities it has with checkmk.

1 Like

hello, i finished the plugin “recently” after testing it in production it worked correctly. now, i would like to be able to create the deployment part of the plugin, i mean.
Setup > Agents > Windows, Linux, Solaris, AIX > Agent rules
I can look at the examples of those plugins that are already configured, but I don’t know if it is necessary to create another python file.
In short, to do this is only necessary:

  1. the file in: /omd/versions/2.2.0p22.cce/lib/python3/cmk/gui/cee/plugins/wato/agent_bakery/rulespecs/
  2. the plugin itself in:
    /opt/omd/versions/2.2.0p22.cce/share/check_mk/agents/windows/plugins/

As soon as I have it at 100% I will upload it to the exchange and post the link here.

first of all, thank you very much for your help, more specifically to @r.sander and @Dirk for their help.