Hi everyone,
I am currently trying to write a custom notification plugin for cmk. It should send the notification via REST to another application.
I am having trouble finding “real” documentation for exactly that kind of thing - I started by:
- copying
share/check_mk/notifications/servicenow
tolocal/share/check_mk/notifications/myservicenow
- Changing line 3 from
# Servicenow (Enterprise only)
to# My Servicenow example
- Added the following to the end of the file:
print("outside: about to check for __main__ == %s" % __name__)
if __name__ == "__main__":
__pickle(str("a"), name="__main__")
print("outside: about to call main()")
sys.exit(main())
I got these instructions from This KB article.
The thing is: Generally, it seems to work. But, as it is with developing something new, I must change stuff quite regularly, re-run it, see the results, repeat.
I am facing the following issues with this (aka. “My Questions” ):
I added a function in my notification plugin, which creates a sub-folder using pathlib.Path.mkdir()
(in /tmp
), which uses pickle
to save the request and json objects into files to have a chance to analyse what’s going on:
def __get_debug_path(marker: str = None): # noqa
from pathlib import Path
debug_dir = Path("/tmp/cmk_myservicenow")
debug_dir.mkdir(exist_ok=True)
if marker is not None:
with open(debug_dir.joinpath('%s.marker' % marker), 'w') as _:
pass
return debug_dir
def __pickle(obj, name: str): # noqa
import pickle
with open(__get_debug_path(name).joinpath("%s.pickle" % name), "wb") as f:
pickle.dump(obj, f)
From the main()
function, I then call this multiple times for interesting object extraction:
__pickle(context, name="context")
__pickle(context.json_for_event, name="context_json_for_event")
__pickle(response, name="response")
The idea behind that is clear - it just does not happen: Neither the folder in /tmp
is created, nor are the pickle files written. At the same time, also no exception is thrown or at least I do not find it in the logs.
I then tried to find the reason for this not working, changed lots of stuff, even re-started the site multiple times, and deleted all __pycache__
folders, … During my search, I even changed the path where the files are written to. After hours, at least the folder was created, but to the path which was previously in there and not the current one …
It feels like there is some really weird caching going on or the updated script is executed by another satellite, which does not always receive the latest version of the script.
Long story short:
I don’t understand how cmk executes these notification plugins:
- Is it executing them as a script? Or does it import specific classes and functions only?
- Where do these scripts get their parameters from for the content of the notifications?
- Which node is executing these notification plugins? Is that done by the central cmk instance or is the satellite which this node is linked to executing it?
- What logs are potential notification script exceptions written to?
- Is there anything to mind for when changing a notification script? I think I already identified that it is required to change something in the notification rules (like the
Comment
field), to triggerpending changes
for all sites, so that the latest version of the script is distributed via configuration replication. Is there anything else that needs to be taken care for?