Admins often forget to set downtimes, when they “just reboot” a server, so I created a simple systemd service that makes a host set itself into a short downtime on reboots.
Maybe this is also useful for others…
[Unit]
Description=Set CMK downtime on reboot
After=network.target
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStartPre=/bin/bash -c "/bin/systemctl set-environment hostname_short=$(/bin/hostname -s)"
ExecStop=/bin/curl -m 30 "https://<CMK URL>/<INSTANCE>/check_mk/view.py?_username=<AUTOMATION USER>&_secret=<SECRET>&_transid=-1&_do_confirm=yes&_do_actions=yes&host=${hostname_short}&_down_from_now=yes&_down_minutes=<DOWNTIME LENGTH>&_down_comment=<COMMENT>&view_name=hoststatus"
StandardOutput=null
StandardError=null
[Install]
WantedBy=multi-user.target
Edit this file with your CMK enviroment settings for URL, instance, user and secret. Add a downtime comment and set the desired length of the downtime.
Then save it to /etc/systemd/system/set_cmk_downtime.service.
Reload systemd “systemctl daemon-reload” and enable/start the service “systemctl enable --now set_cmk_downtime.service”
The service assumes the system’s short hostname (without domain) is the same as the hostname in CMK. If not you have to manually configure the hostname.