Change output of printer check from unknown to Ok

CMK version: 2.4.0p17 community version
OS version:Rocky Linux 9.7

i have a brother printer which shows the following alert:
unknown alert group 0#0: Slaapstand

i think the problem is related to the dutch word of Slaapstand instead of sleep and is shown as UNKN or unknown

i tried to create an overwrite in the file ~/local/lib/check_mk/plugins/agent_based/printer_alerts.py after copy of the original file but this failed. I think because the check is SNMP based and not agent based

can someone help me to change the alert to an known ok state ?

i am no crack in omd so please be gentle and give me exact pointers where i need to change what :wink:

Hope that someone is kind enough to help with this one

The way to do it is with Setup > Services > Service monitoring rules > Service State Translation, but that rule is unavailable in the raw edition.
An example of this rule can be seen here: Service State Translation upon Summary instead of Service Name - #4 by StefanM

I don’t think the Dutch Slaapstand is causing the warning, but more the code / value attached to it. There is a rule called Setup > Services > Service monitoring rules > Translation of service descriptions, but the help suggests that it will only make user friendly descriptions, the state will remain the same.

I also found the rule Setup > Services > Service monitoring rules > Generic String, but it lacks real documentation or examples what it actually does.

Checkmk AI says folllowing about it, which gives a bit of hope:

The generic string rule in Checkmk is used to define how string values from checks are processed and interpreted. It allows you to specify patterns and conditions to match string output from checks and then assign states, labels, or other attributes based on those matches.

In essence, the generic string rule helps you customize the interpretation of string results from various checks, enabling more precise monitoring and alerting based on textual data.

I tried this rule on my printer so stuff would go to a warning state when KYOCERA is mentioned, but I can’t get it to work on my 2.1.0.p5.cre.

Maybe you can get it to work in your newer version, or somebody else can help you further with your issue.

1 Like

wow, perfect explanation .. many thanks for that. I tried it but i am not quite sure how the string is interpreted. I tried using exact string value like Slaapstand and using wildcards e.g. *Slaapstand * but the status will not change

I don’t understand how the string is interpreted either. I would assume it does exact string or a regular expression. But result is the same as yours, the status remains unchanged.

I set this rule explicit on my printer host, so I wouldn’t have weird outcomes on other hosts. But the weird thing is, the rule is not to be found in the hamburger menus Parameters for this ... of the host and its services, which lists all the rules that affect it.


I couldn’t find it other than in Setup > Services > Service monitoring rules > Generic String where I initially made it.

So some documentation on actual use of this rule would be nice.

Hello,

since @Yggy mentioned my name, I got aware of this thread.

I’m not sure if Checkmk picks up your check in that path. I overwrite checks (and borough parts of checks) regularly and I have no problem even with redirecting this to other “parts” of Checkmk (e.g. I redirect the serials from the plugin outputs to the inventory of the host).

The correct path for 2.4 should be:
~/local/lib/python3/cmk_addons/plugins/kyocera_alerts/agent_based/printer_alerts.py

“kyocera_alerts” can be named different if you like.

Leave this part from the original file

check_plugin_printer_alerts = CheckPlugin(
    name=“printer_alerts”,
    service_name=“Alerts”,
    discovery_function=discovery_printer_alerts,
    check_function=check_printer_alerts,
)

identical and your check will overwrite the shipped one.

Greetings
Stefan

1 Like

many thanks for the share, just to be sure i follow it correctly and what i did so far:

sudo su <mysite>

mkdir -p ~/local/lib/python3/cmk_addons/plugins/brother_alerts/agent_based

cp ~/lib/check_mk/plugins/collection/agent_based/printer_alerts.py ~/local/lib/python3/cmk_addons/plugins/brother_alerts/agent_based/

vi ~/local/lib/python3/cmk_addons/plugins/brother_alerts/agent_based/printer_alerts.py

I added in the file under PRINTER_CODE_MAP: Final the following section:
PRINTER_ALERTS_TEXT_MAP: Final = {
“Energiesparen”: State.OK,
“Sleep”: State.OK,
“Slaapstand”: State.OK,
}

now when i run cmk -R i get the following error:

OMD[lexit]:~$ cmk -R
Error in agent based plugin: cmk_addons.plugins.brother_alerts.agent_based.printer_alerts:snmp_section_printer_alerts: plug-in ‘printer_alerts’ already defined at cmk.plugins.collection.agent_based.printer_alerts:snmp_section_printer_alerts
Error in agent based plugin: cmk_addons.plugins.brother_alerts.agent_based.printer_alerts:check_plugin_printer_alerts: plug-in ‘printer_alerts’ already defined at cmk.plugins.collection.agent_based.printer_alerts:check_plugin_printer_alerts
Generating configuration for core (type nagios)…

So at least i am now getting information that the file will be read and used which i never got before but now it is complaining that the alerts are allready defined.

Do i need to create an emtpy file with just my changes ? or did i do something wrong ?

to be sure i removed my initial trial file ~/local/lib/check_mk/plugins/collection/printer_alerts.py so this could not get in the way

I managed to get it working :smiley:

i did the following:
sudo su - <sitename>
mkdir -p ~/local/lib/check_mk/plugins/collection/agent_based/
cp ~/lib/check_mk/plugins/collection/agent_based/printer_alerts.py ~/local/lib/check_mk/plugins/collection/agent_based/printer_alerts.py

vi ~/local/lib/check_mk/plugins/collection/agent_based/printer_alerts.py

changed the section:

PRINTER_ALERTS_TEXT_MAP: Final = {
“Energiesparen”: State.OK,
“Sleep”: State.OK,
“Slaapstand”: State.OK,
}

in this section i added the line “Slaapstand”: State.OK,

saved the file and run cmk -R
and checked using cmk -nv brtl3550cdw

where brtl3550cdw is the name of my printer device in checkmk

the warning was nog gone and the check entered the Ok state

just to be sure to test if the file is interpreted i added first the following code in the python file before i did any changes:
import sys
sys.stderr.write(“### USING LOCAL printer_alerts OVERRIDE ###\n”)

when running the check command cmk -nv brtl3550cdw it finaly showed the text ### USING LOCAL printer_alerts OVERRIDE ###so i knew the file was used. After this i removed the message and changed my check and presto

many thanks for the support and hopefully someone else can take the lessons learned

2 Likes