broker_module=${pkgs.status_engine.module}/lib/status-engine/naemon/statusengine-${pkgs.naemon.status_engine_version}.o use_service_perfdata=1 use_process_data=0 use_system_command_data=0 use_external_command_data=0 use_flapping_data=0 use_program_status_data=0 use_notification_data=0 use_contact_status_data=0 use_contact_notification_data=0 use_event_handler_data=0 use_object_data=0
'';
extraResource = let
- resources = lib.mapAttrsToList (k: v: v.resources or {}) mypluginsConfig;
+ resources = [hostObjects.resources or {}] ++ (lib.mapAttrsToList (k: v: v.resources or {}) mypluginsConfig);
joined = lib.zipAttrsWith (n: v: if builtins.length (lib.unique v) == 1 then builtins.head v else abort "Non-unique resources names") resources;
joinedStr = builtins.concatStringsSep "\n" (lib.mapAttrsToList (k: v: "$" + "${k}$=${v}") joined);
in ''
postgresql = {
commands = {
check_postgresql_replication = "${sudo} -u postgres $USER2$/check_postgres_replication \"$ARG1$\" \"$ARG2$\" \"$ARG3$\"";
+ check_postgresql_database_count = "$USER2$/check_postgres_database_count \"$ARG1$\" \"$ARG2$\" \"$ARG3$\"";
};
chunk = let
postgresqlBinary = if config.myServices.databasesReplication.postgresql.enable
wrapProgram $out/check_postgres_replication --prefix PATH : ${lib.makeBinPath [
postgresqlBinary
]}
+ cp ${./plugins}/check_postgres_database_count $out/
+ patchShebangs $out/check_postgres_database_count
+ wrapProgram $out/check_postgres_database_count --prefix PATH : ${lib.makeBinPath [
+ postgresqlBinary
+ ]}
'';
sudo = myplugins: {
_webstatus_url = "https://cloud.immae.eu";
}
+ {
+ service_description = "nextcloud website is running on nextcloud.4c.salle-s.org";
+ host_name = "quatresaisons.immae.eu";
+ use = "external-web-service";
+ check_command = ["check_https" "nextcloud.4c.salle-s.org" "/" "a safe home for all your data"];
+
+ servicegroups = "webstatus-webapps";
+ _webstatus_name = "Nextcloud";
+ _webstatus_url = "https://nextcloud.4c.salle-s.org";
+ }
+
{
service_description = "davical website is running on dav.immae.eu";
host_name = "eldiron.immae.eu";
-{ lib, hostFQDN, emailCheck, ... }:
+{ lib, hostFQDN, emailCheck, openldap, ... }:
let
defaultPassiveInfo = {
filter = lib.attrsets.filterAttrs
};
in
{
- activatedPlugins = [ "megaraid" ];
+ resources = {
+ USER212 = "{{ .monitoring.quatresaisons.naemon_ldap }}";
+ };
+ activatedPlugins = [ "megaraid" "command" "postgresql" ];
service = [
{
passiveInfo = defaultPassiveInfo // { servicegroups = "webstatus-resources"; };
use = "local-service";
check_command = ["check_megaraid"];
}
+ {
+ passiveInfo = defaultPassiveInfo // { servicegroups = "webstatus-resources"; };
+ service_description = "LDAP is running";
+ use = "local-service";
+ check_command = [ "check_command_status" "${openldap}/bin/ldapwhoami -D uid=naemon,ou=services,dc=salle-s,dc=org -w $USER212$" "0" ""];
+ }
+ {
+ passiveInfo = defaultPassiveInfo // { servicegroups = "webstatus-resources"; };
+ service_description = "Postgresql is running";
+ use = "local-service";
+ check_command = [ "check_postgresql_database_count" "/run/postgresql" "5432" "3" ];
+ }
];
}
--- /dev/null
+#!/bin/bash
+
+STATE_OK=0
+STATE_WARNING=1
+STATE_CRITICAL=2
+STATE_UNKNOWN=3
+
+host=$1
+port=$2
+min=$3
+
+count=$(psql -h $host -p $port -A -q -c '\t' -c 'select count(datname) from pg_catalog.pg_database' postgres 2>&1)
+exit_code=$?
+
+if [[ $exit_code -ne 0 ]]; then
+ echo "UNKNOWN - Impossible to run psql command: $count"
+ exit $STATE_UNKNOWN
+elif [[ -z "$count" ]]; then
+ echo "UNKNOWN - No database found"
+ exit $STATE_UNKNOWN
+else
+ output="Database count is $count"
+ LC_ALL=C count=$(printf "%.*f" 0 $count)
+
+ if [[ $count -gt $min ]]; then
+ echo "OK - $output | count=${count};$min;$min;0;"
+ exit $STATE_OK
+ else
+ echo "CRITICAL - $output | count=${count};$min;$min;0;"
+ exit $STATE_CRITICAL
+ fi
+fi
in {
services.postgresql.enable = true;
services.postgresql.package = pkgs.postgresql_12;
+ services.postgresql.ensureUsers = [
+ { name = "naemon"; }
+ ];
secrets.keys = [
{
dest = "ldap/password";
-Subproject commit bf72e9cc77b6c2217ae9e9a272805b1d917336c3
+Subproject commit 36233b7f760f9a3a20b8684e1f04b1b3a54c28f1