A simple charm that shows how to implement some monitoring with charmhelpers and nrpe to use with nagios.
Uses charmhelpers lib to work out the nrpe bits. See: https://github.com/juju/charm-helpers
charmcraft build
juju add-model examples
juju model-config default-series=focal
juju model-config logging-config="<root>=WARNING;unit=TRACE"
juju deploy nagios
juju deploy nrpe
juju deploy ./monitoring-nrpe.charm
juju relate nagios:monitors nrpe:monitors
juju relate monitoring-nrpe:local-monitors nrpe
# Visit nagios http://nagios
# Get nagiosadmin password:
juju ssh nagios/0 sudo cat /var/lib/juju/nagios.passwd
-
Update metadata.yaml
provides: local-monitors: interface: local-monitors scope: container
-
Add the following to config.yaml
nagios_context: default: "juju" type: string description: | Used by the nrpe subordinate charms. A string that will be prepended to instance name to set the host name in nagios. So for instance the hostname would be something like: juju-myservice-0 If you're running multiple environments with the same services in them this allows you to differentiate between them. nagios_servicegroups: default: "" type: string description: | A comma-separated list of nagios servicegroups. If left empty, the nagios_context will be used as the servicegroup
-
Add custom checks (Nagios plugins) to files/nrpe-checks
files/nrpe-checks/check_mycheck.sh
-
Implement the events in charm.py with something like in this charm
def render_checks(self): """Render nrpe checks.""" nrpe = NRPE() if not os.path.exists(self.plugins_dir): os.makedirs(self.plugins_dir) # register basic test nrpe.add_check( shortname="hellocheck", description="Dummy hello check", check_cmd="check_hello.sh", ) nrpe.write()
-
Update charmcraft.yaml
parts: charm: charm-python-packages: [setuptools < 58] prime: - files/*
-
Add to requirements.txt
ops >= 1.3.0 charmhelpers==0.20.24
Erik Lönroth, support me by attributing my work https://eriklonroth.com