Module: check_mk
Branch: master
Commit: d0c194284d2f90eb414fc5b1a259a80597f21815
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d0c194284d2f90…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Wed Feb 6 08:13:05 2019 +0100
7140 FIX postgres_instance: go to state CRIT if psql has been stopped
Change-Id: I7e71b74acacc575e1ff09a17a50a82ae8d80cff4
---
.werks/7140 | 10 ++++++++++
checks/postgres_instances | 17 +++++++----------
checks/postgres_version | 27 ++++++++++++++++-----------
3 files changed, 33 insertions(+), 21 deletions(-)
diff --git a/.werks/7140 b/.werks/7140
new file mode 100644
index 0000000..b19f994
--- /dev/null
+++ b/.werks/7140
@@ -0,0 +1,10 @@
+Title: postgres_instance: go to state CRIT if psql has been stopped
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1549437078
+Class: fix
+
+
diff --git a/checks/postgres_instances b/checks/postgres_instances
index 199b466..8c0ffdf 100644
--- a/checks/postgres_instances
+++ b/checks/postgres_instances
@@ -47,29 +47,26 @@ def parse_postgres_instances(info):
if line[0].startswith("[[[") and line[0].endswith("]]]"):
db_id = line[0][3:-3]
is_single = True
+ parsed.setdefault(db_id.upper(), {})
elif len(line) >= 4:
if not is_single:
db_id = line[3].split("/")[-1]
- parsed.setdefault(db_id.upper(), {"pid": line[0]})
+ parsed.update(db_id.upper(), {"pid": line[0]})
return parsed
-def inventory_postgres_instances(parsed):
- for db_id in parsed:
- yield db_id, None
-
-
-def check_postgres_instances(item, params, parsed):
- if item in parsed:
- return 0, "Status: running with PID %s" %
parsed[item]["pid"]
+def check_postgres_instances(item, _no_params, parsed):
+ pid = parsed.get(item, {}).get("pid")
+ if pid is not None:
+ return 0, "Status: running with PID %s" % pid
return 2, "Instance %s not running" % item
check_info['postgres_instances'] = {
'parse_function': parse_postgres_instances,
- 'inventory_function': inventory_postgres_instances,
+ 'inventory_function': discover(),
'check_function': check_postgres_instances,
'service_description': 'PostgreSQL Instance %s',
}
diff --git a/checks/postgres_version b/checks/postgres_version
index 73db616..072d77d 100644
--- a/checks/postgres_version
+++ b/checks/postgres_version
@@ -26,11 +26,19 @@
# <<<postgres_version>>>
# PostgreSQL 9.3.6 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.2-19ubuntu1)
4.8.2, 64-bit
-
-# instance
+#
+# # instance
# <<<postgres_version>>>
# [[[foobar]]]
# PostgreSQL 9.3.6 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.2-19ubuntu1)
4.8.2, 64-bit
+#
+# # In case the server has been stopped:
+# <<<postgres_version:sep(1)>>>
+#
+# psql: could not connect to server: No such file or directory
+# Is the server running locally and accepting
+# connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5437"?
+#
def parse_postgres_version(info):
@@ -44,19 +52,16 @@ def parse_postgres_version(info):
return parsed
-def inventory_postgres_version(parsed):
- for instance in parsed:
- yield instance, None
-
-
-def check_postgres_version(item, _no_params, parsed):
- if item in parsed:
- yield 0, parsed[item]
+@get_parsed_item_data
+def check_postgres_version(_no_item, _no_params, data):
+ if "could not connect" in data:
+ raise MKCounterWrapped("Login into database failed")
+ yield 0, data
check_info['postgres_version'] = {
"parse_function": parse_postgres_version,
- "inventory_function": inventory_postgres_version,
+ "inventory_function": discover(),
"check_function": check_postgres_version,
"service_description": "PostgreSQL Version %s",
}