Add PostgreSQL check

This commit is contained in:
Jan Dittberner 2023-08-18 14:15:32 +02:00
parent 9eb77fe941
commit 04fbc78f11
3 changed files with 64 additions and 4 deletions

View file

@ -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"
}

View file

@ -18,8 +18,6 @@ apply Service "disk " for (disk => config in host.vars.disks) {
check_command = "disk" check_command = "disk"
vars += config vars += config
assign where host.vars.disks
} }
apply Service for (http_vhost => config in host.vars.http_vhosts) { apply Service for (http_vhost => config in host.vars.http_vhosts) {
@ -46,6 +44,14 @@ apply Service "load" {
assign where host.name == NodeName 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" { apply Service "ping4" {
import "generic-service" import "generic-service"
@ -76,8 +82,6 @@ apply Service "proc-" for (proc => config in host.vars.procs) {
check_command = "procs" check_command = "procs"
vars += config vars += config
assign where host.vars.disks
} }
apply Service "ssh" { apply Service "ssh" {

View file

@ -106,4 +106,8 @@ object Host "beholder" {
procs_command = "postgres" procs_command = "postgres"
procs_critical = "1:50" procs_critical = "1:50"
} }
vars.pgsql_dbs["icingadb"] = {
pgsql_query = "SELECT COUNT(*) FROM host"
}
} }