Own check for monitoring total disk usage of a host not working

Hello,
I am new to Check_MK and I am using Check_Mk raw.
I try to create a check, which shows the total disk usage of all disks of a host.

The script on the monitored host at /user/lib/check_MKagent/plugins/
contains this:

#!/bin/sh
echo ‘<<<filesystem_df_total_>>>’
df -h --output=size --total | awk ‘END {print $1}’

If I try the output of the check with “check_mk_agent | less” I can find the output of the check “filesystem_df_total” which shows the disk usage in TB

So I created the plugin at the check_mk Server in /opt/omd/sites/sitename/local/lib/check_mk/base/plugins/agent_based

It contains: from .agent_based_api.v1 import *

def discover_filesystem_df_total(section):
yield Service()

register.check_plugin(
name=“filesystem_df_total”,
service_name=“Filesystem df_total”,
discovery_function=discover_filesystem_df_total,
check_function=check_Filesystem_df_total,

But there is no new Service check at the new host.
Am I missing something?

Can you help me please?

Thank you in advance.

kind regards,
cmk_User

Hi.

I think you need the following register settings:

def discover_filesystem_df_total(section):
    yield Service(item="Filesystem total")

register.check_plugin(
    name=“filesystem_df_total”,
    service_name=“%s”,
    discovery_function=discover_filesystem_df_total,    
    check_function=check_Filesystem_df_total,
)

RG, Christian

Thank you for the fast reply.

I tried your suggested modifications, but there is still no service check appearing.

Hi.

I hink you need to register also the agent section like this:

def parse_filesystem_df_total(string_table):
    section = string_table
    return section if section else None

register.agent_section(
    name = '_filesystem_df_total',
    parse_function = parse_filesystem_df_total,
)

RG, Christian

Thank you again for you fast reply.

I edited the script like you suggested, but there is still no service check appearing.
It looks like this now:

from .agent_based_api.v1 import *

def discover_filesystem_df_total(section):
yield Service(item=“Filesystem total”)

register.check_plugin(
name=“filesystem_df_total”,
service_name=“%s”,
discovery_function=discover_filesystem_df_total,
check_function=check_Filesystem_df_total,
)

def parse_filesystem_df_total(string_table):
section = string_table
return section if section else None

register.agent_section(
name = ‘_filesystem_df_total’,
parse_function = parse_filesystem_df_total,
)

Please use the “Preformatted text” like @ChristianM does. Your code is not readable at the moment.

I am sorry. It looks now like this:

from .agent_based_api.v1 import *

def discover_filesystem_df_total(section):
yield Service(item=“Filesystem total”)

register.check_plugin(
name=“filesystem_df_total”,
service_name=“%s”,
discovery_function=discover_filesystem_df_total,
check_function=check_Filesystem_df_total,
)

def parse_filesystem_df_total(string_table):
section = string_table
return section if section else None

register.agent_section(
name = ‘_filesystem_df_total’,
parse_function = parse_filesystem_df_total,
)

If the code looks like this - it will not work. Python without correct indentation is broken.
Also the strange single and double quotes will not do.
Please copy the text exactly like it is on your CLI into the preformatted text block.

Thank you for the reply.

That is my exact text:

from .agent_based_api.v1 import *

def discover_filesystem_df_total(section):
    yield Service(item="Filesystem total")

register.check_plugin(
    name="filesystem_df_total",
    service_name="%s",
    discovery_function=discover_filesystem_df_total,
    check_function=check_Filesystem_df_total,
)

def parse_filesystem_df_total(string_table):
    section=string_table
    return section if section else None

register.agent_section(
    name="filesystem_df_total",
    parse_function=parse_filesystem_df_total,
)

Hi.
Looks like, there is a typo in the output of the agent:

echo ‘<<<filesystem_df_total_>>>’
df -h --output=size --total | awk ‘END {print $1}’

need to remove the last character of token in the line with the echo, e.g.

#!/bin/sh
echo ‘<<<filesystem_df_total>>>’
df -h --output=size --total | awk ‘END {print $1}’

The token must be equal to the name parameter in the register statements.
Now the plugins should detect the data.

RG, Christian

Thank you for finding the typo.
I fixed it, but still no service check

Something must still be wrong.

the agent output looks like this:

#!/bin/sh
echo '<<<filesystem_df_total>>>'
df -h --output=size --total | awk 'END {print $1}'
~

and the file on the monitored host looks like this:

from .agent_based_api.v1 import *

def discover_filesystem_df_total(section):
    yield Service(item="Filesystem total")

register.check_plugin(
    name="filesystem_df_total",
    service_name="%s",
    discovery_function=discover_filesystem_df_total,
    check_function=check_filesystem_df_total,
)

def parse_filesystem_df_total(string_table):
    section=string_table
    return section if section else None

register.agent_section(
    name="filesystem_df_total",
    parse_function=parse_filesystem_df_total,
)

Hi.

In your code, the check function is missing and when you run “cmk --debug -vvII ” you get an exception. The following code wil work:

#!/usr/bin/env python3

from .agent_based_api.v1 import *

def discover_filesystem_df_total(section):
    yield Service(item="Filesystem total")

def check_filesystem_df_total(item, params, section):
    yield Result(state=State.OK, summary="Here Iam")

register.check_plugin(
    name="filesystem_df_total",
    service_name="%s",
    check_default_parameters={},
    discovery_function=discover_filesystem_df_total,
    check_function=check_filesystem_df_total,
)

def parse_filesystem_df_total(string_table):
    section=string_table
    return section if section else None

register.agent_section(
    name="filesystem_df_total",
    parse_function=parse_filesystem_df_total,
)

RG, Christian

Thanks a lot for all the help.

But I’m afraid it is still not working. The cmk --debug command gave no exception.
I also tried to put a “,” after the None in the check function. But that didn’t help either.

#!/usr/bin/env python3

from .agent_based_api.v1 import *

def discover_filesystem_df_total(section):
    yield Service(item="Filesystem total")

def check_filesystem_df_total(item, params, section):
    yield Result(state=State.OK, summary="Here Iam")

register.check_plugin(
    name="filesystem_df_total",
    service_name="%s",
    check_default_parameters={},
    discovery_function=discover_filesystem_df_total,
    check_function=check_filesystem_df_total,
)

def parse_filesystem_df_total(string_table):
    section=string_table
    return section if section else None,

register.agent_section(
    name="filesystem_df_total",
    parse_function=parse_filesystem_df_total,
)

If i use your code, i first get one new check found.

cmk --debug -vvI testhost
  1 filesystem_df_total
SUCCESS - Found 1 services

also the check gave the expected output

cmk --debug -vvn testhost
...
<<<filesystem_df_total>>> / Transition HostSectionParser -> HostSectionParser
...
No persisted sections
  -> Add sections: [... 'filesystem_df_total', ...]
Filesystem total     Here Iam

Thank you all for the help.

Yes, the check is now found.

But it appears to be just a static Check with no script output. The output of the script on the monitored host which should monitor the total disk usage accross all disks is not there.

It just looks like this:

But the intention of the check was to monitor the output of and a statistic of that. The percentage is not needed.

It should be similar to the integrated Filesystem check, but just the total usage in TB

The output of df -h --output=size --total | awk 'END {print $1}’ in the command line is:
1,5T

So the intention was to create a check which outputs this 1,5T and has a statistic of that, where you can see the fluctuation in used space of the disk usage in TB.

Hi.
You need to fill the check function with a check logic. The example was only to bring you on the right way to get the data from the agent and discover the chekcs. Now it’s on you to finish the plugin for your needs. If you want to see only the value you get, you can write the check function like this:

def check_filesystem_df_total(item, params, section):
    yield Result(state=State.OK, summary=f"Total: {section[0][0]}")

RG, Christian

Thank you very much. :grinning:

That was the output I was looking for.

Now I just need to figure out how to create a performance graph out of it.

Hi.

Please have a look in the check API. There you will find the method’s for metrics.It’s a one liner :wink:

RG, Christian

Thank you for the hint.