Skip to content

Commit

Permalink
Merge pull request #3 from lgmu/master
Browse files Browse the repository at this point in the history
Update check_omd.py to python3 and added --heal functionality to automatically restart OMD services
  • Loading branch information
stdevel authored Apr 20, 2021
2 parents 7a241b6 + 5df177e commit e77b973
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 77 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vagrant
__pycache__
83 changes: 55 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

``check_omd`` is a Nagios / Icinga plugin for checking a particular [OMD](http://www.omdistro.org) site's services.

# Requirements
## Requirements

I successfully tested the plugin with OMD site versions 1.20 to 2.70. As the plugin needs to be executed **by the site user**, a sudo rule is needed. A template (*``check_omd-sudo-template``*) is part of the repository.

# Usage
## Usage

By default, the script checks all services of the site - it is also possible to exclude services if they are predicted to fail in your environment (*``-x`` / ``--exclude`` parameters*).

The following parameters can be specified:
Expand All @@ -18,70 +20,86 @@ The following parameters can be specified:
| `-h` / `--help` | shows help and quits |
| `-w` / `--warning` | defines one or more services that only should throw a warning if not running (*useful for fragile stuff like npcd*) |
| `-x` / `--exclude` | excludes a particular service from the check |
| `-H` / `--heal` | automatically restarts the services that are not running |
| `--version` | prints programm version and quits |

## Examples

The following example indicates an running OMD site:
```
$ ./check_omd.py

```shell
$ ./check_omd.py
OK: OMD site 'stankowic' services are running.
```

A site with a failed ``nagios`` service:
```
$ ./check_omd.py

```shell
$ ./check_omd.py
CRITICAL: OMD site 'hansel' has failed service(s): 'nagios'
```

OMD site ``giertz`` with a well-known daemon, that's crashing sometimes:
```

```shell
$ ./check_omd.py -x npcd
OK: OMD site 'giertz' services are running.
```

OMD site ``clpmchn``, excluding npcd from throwing critical states:
```

```shell
$ ./check_omd.py -w npcd
WARNING: OMD site 'clpmchn' has service(s) in warning state: 'npcd'
```

# Installation
## Installation

To install the plugin, move the Python script, the agent configuration and sudo rule into their appropriate directories. The paths may vary, depending on your Linux distribution and architecture. For RPM-based distribtions, proceed with the following steps:
```

```shell
# mv check_omd.py /usr/lib64/nagios/plugins
# mv check_omd-sudo-template /etc/sudoers.d/
# chmod +x /usr/lib64/nagios/plugins/check_omd.py
# chmod 0440 /etc/sudoers.d/check_omd-sudo-template
```

When using NRPE, copy the appropriate configuration and restart the daemon:
```

```shell
# mv check_omd.cfg /etc/nrpe.d/
# service nrpe restart
```

When using Icinga2, copy the configuration to **ITL** (*Icinga Template Library*), e.g.:
```

```shell
# cp check_omd.conf /usr/share/icinga2/include/plugins-contrib.d/
# service icinga2 restart
```

Make sure to alter the sudo configuration to match your OMD site name, e.g.:
```

```shell
nrpe ALL = (stankowic) NOPASSWD: /usr/lib64/nagios/plugins/check_omd.py
```

It also possible to create a RPM file for your Linux distribution with the RPM spec file:
```

```shell
$ rpmbuild -ba nagios-plugins-check_omd.spec
...
```

The RPM spec has been tested on Enterprise Linux 5 to 7, i386 and x86_64. Currently, the RPM package only includes NRPE-related configuration, Icinga2 will follow.

# Configuration
## Configuration

### Nagios / Icinga 1.x

## Nagios / Icinga 1.x
Inside Nagios / Icinga you will need to configure a remote check command, e.g. for NRPE:
```

```text
#check_nrpe_omd
define command{
command_name check_nrpe_omd
Expand All @@ -90,7 +108,8 @@ define command{
```

Configure the check for a particular host, e.g.:
```

```text
#SRV: omd stankowic
define service{
use generic-service
Expand All @@ -100,9 +119,11 @@ define service{
}
```

## Icinga2
### Icinga2

Define a service like this:
```

```text
apply Service for (SITE => config in host.vars.omd_sites) {
import "generic-service"
check_command = "check_omd"
Expand All @@ -116,7 +137,8 @@ apply Service for (SITE => config in host.vars.omd_sites) {
```

Create ``omd_site`` dictionaries for your hosts and assign the ``app`` variable:
```

```text
object Host "st-mon04.stankowic.loc" {
import "linux-host"
...
Expand All @@ -131,23 +153,28 @@ object Host "st-mon04.stankowic.loc" {
```

Validate the configuration and reload the Icinga2 daemon:
```

```shell
# icinga2 daemon -C
# service icinga2 reload
```

# Troubleshooting
## Plugin not executed as OMD site user
## Troubleshooting

### Plugin not executed as OMD site user

The plugin will not work if is not executed as site user:
```

```shell
$ whoami
taylor
$ ./check_omd.py
$ ./check_omd.py
UNKNOWN: unable to check site: 'omd: no such site: taylor' - did you miss running this plugin as OMD site user?
```

An error message like this will be displayed if multiple OMD sites are available and you're running the plugin as root:
```
An error message like this will be displayed if multiple OMD sites are available and you're running the plugin as `root`:

```shell
# ./check_omd.py
UNKOWN: unable to check site, it seems this plugin is executed as root (use OMD site context!)
````
Loading

0 comments on commit e77b973

Please sign in to comment.