From 04fbc78f112613dbc828dd6da593ab227a2b29c8 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Fri, 18 Aug 2023 14:15:32 +0200 Subject: [PATCH] Add PostgreSQL check --- global-templates/commands.conf | 52 ++++++++++++++++++++++++++++++++++ global-templates/services.conf | 12 +++++--- master/hosts.conf | 4 +++ 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 global-templates/commands.conf diff --git a/global-templates/commands.conf b/global-templates/commands.conf new file mode 100644 index 0000000..4f35be6 --- /dev/null +++ b/global-templates/commands.conf @@ -0,0 +1,52 @@ +// vim: set ft=icinga2 et sw=2 ts=2 si ai: + +/* +* Checks a local PostgreSQL database. You need to grant the given user +* (normally nagios, which is what Icinga is running as) privileges to connect +* the specified database (or 'template1') and optionally execute the specified +* query. +*/ +object CheckCommand "pgsql_socket" { + command = [ PluginDir + "/check_pgsql" ] + + arguments = { + "-d" = { + value = "$pgsql_database$" + description = "Database to check (default: template1)" + } + "-l" = { + value = "$pgsql_username$" + description = "Login name of user" + } + "-o" = { + value = "$pgsql_options$" + description = "Connection parameters (keyword = value), see below" + } + "-w" = { + value = "$pgsql_warning$" + description = "Response time to result in warning status (seconds)" + } + "-c" = { + value = "$pgsql_critical$" + description = "Response time to result in critical status (seconds)" + } + "-t" = { + value = "$pgsql_timeout$" + description = "Seconds before connection times out (default: 10)" + } + "-q" = { + value = "$pgsql_query$" + description = "SQL query to run. Only first column in first row will be read" + } + "-W" = { + value = "$pgsql_query_warning$" + description = "SQL query value to result in warning status (double)" + } + "-C" = { + value = "$pgsql_query_critical$" + description = "SQL query value to result in critical status (double)" + } + } + + vars.pgsql_username = "nagios" +} diff --git a/global-templates/services.conf b/global-templates/services.conf index a98f7ec..dfbf61a 100644 --- a/global-templates/services.conf +++ b/global-templates/services.conf @@ -18,8 +18,6 @@ apply Service "disk " for (disk => config in host.vars.disks) { check_command = "disk" vars += config - - assign where host.vars.disks } apply Service for (http_vhost => config in host.vars.http_vhosts) { @@ -46,6 +44,14 @@ apply Service "load" { assign where host.name == NodeName } +apply Service "pgsql " for (name => config in host.vars.pgsql_dbs) { + import "generic-service" + + check_command = "pgsql_socket" + + vars += config +} + apply Service "ping4" { import "generic-service" @@ -76,8 +82,6 @@ apply Service "proc-" for (proc => config in host.vars.procs) { check_command = "procs" vars += config - - assign where host.vars.disks } apply Service "ssh" { diff --git a/master/hosts.conf b/master/hosts.conf index be7e748..4367c33 100644 --- a/master/hosts.conf +++ b/master/hosts.conf @@ -106,4 +106,8 @@ object Host "beholder" { procs_command = "postgres" procs_critical = "1:50" } + + vars.pgsql_dbs["icingadb"] = { + pgsql_query = "SELECT COUNT(*) FROM host" + } }