From 94a8302228d0ae3df1483fac8e3ebc4da7e952dc Mon Sep 17 00:00:00 2001
From: Dennis Ahrens <dennis.ahrens@hs-hannover.de>
Date: Mon, 17 Aug 2020 12:28:14 +0200
Subject: [PATCH] A little helper that notifies about remaining lib IDs

---
 README.md                                        | 4 ++++
 checkmk/custom-files/local/remaining_library_ids | 5 +++++
 checkmk/debian/remaining_library_ids             | 7 +++++++
 3 files changed, 16 insertions(+)
 create mode 100644 checkmk/custom-files/local/remaining_library_ids
 create mode 100644 checkmk/debian/remaining_library_ids

diff --git a/README.md b/README.md
index 215cc69..b9188d7 100644
--- a/README.md
+++ b/README.md
@@ -104,3 +104,7 @@ Installs the radsec plugin.
 ### `checkmk.debian.smart`
 
 Installs the [smart.stats](https://checkmk.com/cms_check_smart.stats.html) agent plugin
+
+### `checkmk.debian.remaining_library_ids`
+
+Install a small local check that asks hshifo about remaining library ids - needs to run on pgdb
diff --git a/checkmk/custom-files/local/remaining_library_ids b/checkmk/custom-files/local/remaining_library_ids
new file mode 100644
index 0000000..0376a00
--- /dev/null
+++ b/checkmk/custom-files/local/remaining_library_ids
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+REMAINNG = $(sudo -u postgres -- psql -qtAX -d hshinfo -c "select (maximum_value::bigint - (SELECT last_value FROM hshinfo.seq_raw_library_id)) from information_schema.sequences where sequence_schema = 'hshinfo' and sequence_name = 'seq_raw_library_id';")
+
+echo "P remaining_library_ids=$REMAINING;400:;200: That many library IDs are available."
\ No newline at end of file
diff --git a/checkmk/debian/remaining_library_ids b/checkmk/debian/remaining_library_ids
new file mode 100644
index 0000000..6fe076a
--- /dev/null
+++ b/checkmk/debian/remaining_library_ids
@@ -0,0 +1,7 @@
+hsh_checkmk_library_ids_local:
+  file.managed:
+    - name: /usr/lib/check_mk_agent/local/remaining_library_ids
+    - source: salt://checkmk/custom-files/local/remaining_library_ids
+    - mode: 755
+    - user: root
+    - group: root
\ No newline at end of file
-- 
GitLab