From cac41ad950e66b755f8c768c11cff82c2dad4aa7 Mon Sep 17 00:00:00 2001
From: BaranekD <0Baranek.dominik0@gmail.com>
Date: Fri, 27 Aug 2021 10:14:26 +0200
Subject: [PATCH] feat: Added metadata_expiration.py script

---
 README.md              |  8 +++++++-
 metadata_expiration.py | 14 ++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 metadata_expiration.py

diff --git a/README.md b/README.md
index 57d9c11..4087d0c 100644
--- a/README.md
+++ b/README.md
@@ -14,4 +14,10 @@ All nagios scripts are located under `nagios` directory.
 * Do mysqldump into `/opt/mariadb_backup` and remove all dump file older than 7 days
 
 ### separate_oidc_logs.py
-* Script for remove all logs from test accounts from OIDC logs
\ No newline at end of file
+* Script for remove all logs from test accounts from OIDC logs
+
+### metadata_expiration.py
+* This script checks whether there are some metadata close to expiration date
+
+* Params:
+  * 1 - url to a page which prints a time when expires the metadata closest to expiration
\ No newline at end of file
diff --git a/metadata_expiration.py b/metadata_expiration.py
new file mode 100644
index 0000000..cd1b68d
--- /dev/null
+++ b/metadata_expiration.py
@@ -0,0 +1,14 @@
+import sys
+from urllib.request import urlopen
+from bs4 import BeautifulSoup
+
+url = sys.argv[1]
+html = urlopen(url).read()
+closest_expiration = BeautifulSoup(html, "html.parser")
+
+if float(closest_expiration.text) >= 24:
+    print('0 metadata_expiration - OK (' + closest_expiration.text + ')')
+elif float(closest_expiration.text) >= 12:
+    print('1 metadata_expiration - WARNING (' + closest_expiration.text + ')')
+else:
+    print('2 metadata_expiration - CRITICAL (' + closest_expiration.text + ')')
-- 
GitLab