# CheckMK Operation

Monitoring in the department is done with *agents* and a central monitor, located at https://monitor.cms.caltech.edu/CMS.

Every system that is to be monitored must be first registered into the system, and then probed for services, before any polling can occur.
CheckMK operates fundamentally as multi-tenant, meaning that more than one "site" can be monitoried from the same server instance.
Therefore, to create a CheckMK monitoring service, a "site" will be referenced at each agent (client).

#### Agent Installation
The Checkmk server creates agent packages for each type of possible agent, located in the menu,   
`Setup` --> `Agents` --> And the OS of the endpoint to be monitored.

Debian-based (deb) and RedHat-based (rpm) packages are both under `Linux`.  
Download this package file onto the agent, and then install it via the local package management tool.  
This is typically found:
**Debian/Ubuntu (deb)**
```
https://monitor.cms.caltech.edu/CMS/check_mk/agents/check-mk-agent_2.3.0p31-1_all.deb
```
**RedHat/SUSE (rpm)**
```
https://monitor.cms.caltech.edu/CMS/check_mk/agents/check-mk-agent-2.3.0p31-1.noarch.rpm
```
Upon install, the agent should be running, so now we must create the host in Checkmk.  
`Setup` --> `Hosts` --> `Hosts`  
Go to the appropriate Folder for the endpoint, and then `Add Host`.  
Fill out the appropriate info about the host, e.g., if the host runs SNMP, then check the box for SNMP, etc.  
Back on the endpoint (host/client), the host must be registered, so that it knows which server, which site, and create/accept all the TLS certificates to communicate.  
This is done with the command on the agent:  
```
cmk-agent-ctl register --server monitor --site CMS --user cmkadmin --hostname `hostname`
```
which will register the host on the monitor server under the CMS site, using the cmkadmin user.  The user's password will be prompted.

Back on the server, a service discovery will need to be run, to begin actually monitoring the new host.  
This is done through the `Save & run service discovery` button at the top.

*Monitoring* will begin immediately on the newly created agent/host.

#### Notifications
CheckMK has [extensive documentation](https://docs.checkmk.com/latest/en/notifications.html) regarding notifications, and arguably one of the best flapping detection mechanisms in any monitoring solution.  
> [!NOTE]
> *Flapping* refers to the vascillation of state of a given service.
> This often becomes extremely noisy and annoying when a service has an outage then quickly recovers then goes down again over a short time.

Basically, CheckMK uses rules.  For everything.  This includes notifications.  
Hence, the current set of notification rules is:
 1. Email. Notify all contacts of a host/service via HTML email
 2. Slack. Notify all contacts of a host/service via Slack.

Within each rule is specific settings and parameters for the system to notify all contacts associated with each host/service.
These can be viewed/edited inside CheckMK via `Setup` --> `Events` --> `Notification configuration`.  
Regarding Slack, the Slack settings are beyond the scope here, as it involves creating a mechanism inside Slack to be able to handle messages destined to a channel. 

Notifications in CheckMK will escalate if not ***acknowledged***, meaning the system will go onto the next notification channel in the list of notification rules if the outage is neither resolved nor acknowledged via the web UI.  
Simply, following the link of the reported outage in the web UI, and clicking `Acknowledge`, followed by the different options and a comment/explanation.  
CheckMK will then re-notify all contacts the service/host has been acknowledged, whether the state has changed or not (UP or DOWN).

#### Service Rules
Rather than detail every rule for every service, we'll quickly outline a simple example.

Each service, globally or individual host, can be enabled/disabled or have specific thresholds for monitoring.  
For example, we can set the system to **ignore** the size of `.snapshot` in a file system, as the file server manages that, so that each host that has an NFS share mounted, CheckMK will ignore the state of `.snapshot`, including the file server itself.
However, we would also want to monitor the size of file systems for each host, and warn when storage space becomes concerning.  
Each filesystem, for each host, or globally, can be specified as a default, and then set on a per-host basis.  
For example, if we want to be notified with a warning that `/` is at 90% capacity on all hosts, but we don't need to be notified until `/` is at 95% on a host that only has 20GB (as that is 1GB remaining).
Each rule can be declared and overruled in this way, through default service rules and host-specific rules.
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9