From 7a85c9920e6ef003f628f63528451fe84c388735 Mon Sep 17 00:00:00 2001
From: Jan Philipp Timme <jan.philipp@timme.it>
Date: Fri, 7 May 2021 10:09:22 +0200
Subject: [PATCH] Add plugin to check bbb via scalelite

---
 checkmk/custom-files/plugins/checkbbb.py | 114 +++++++++++++++++++++++
 checkmk/debian/checkbbb.sls              |   7 ++
 2 files changed, 121 insertions(+)
 create mode 100644 checkmk/custom-files/plugins/checkbbb.py
 create mode 100644 checkmk/debian/checkbbb.sls

diff --git a/checkmk/custom-files/plugins/checkbbb.py b/checkmk/custom-files/plugins/checkbbb.py
new file mode 100644
index 0000000..dd57859
--- /dev/null
+++ b/checkmk/custom-files/plugins/checkbbb.py
@@ -0,0 +1,114 @@
+#!/usr/bin/python3
+
+#
+# checkbbb.py
+# Frank Schiebel frank@linuxmuster.net
+# GPL v3
+#
+
+import os
+import sys
+import socket
+import re
+import hashlib
+import requests
+from collections import defaultdict
+from xml.dom.minidom import parse, parseString
+
+def getStatus():
+    stream = os.popen('/usr/bin/docker exec  scalelite-api  ./bin/rake status')
+    stream = stream.read()
+    allservers = []
+    for line in stream.splitlines():
+        fields = re.split(r'\s',line)
+        fields = list(filter(None, fields))
+        numfields = len(fields)
+
+        if numfields == 7:
+            hrfields = {}
+            fields[0] = re.split(r'\.',fields[0])[0]
+            hrfields["hostname"] = fields[0]
+            hrfields["state"] = fields[1]
+            hrfields["status"] = fields[2]
+            hrfields["meetings"] = fields[3]
+            hrfields["users"] = fields[4]
+            hrfields["largestmeeting"] = fields[5]
+            hrfields["videos"] = fields[6]
+            allservers.append(hrfields)
+            
+    return allservers
+
+def generateCheckLine(bbb):
+    global totalMeetings
+    global totalAttendees
+    global totalVideousers
+    global avgVideoPerMeeting
+    checkstate = 0 
+    statusline = ""
+
+    if bbb["state"] == "enabled":
+        statusline  = str(checkstate) + " " + "BBB_" + bbb["hostname"] + " "
+        statusline += "numMeetings=" + bbb["meetings"] + "|"
+        statusline += "numAttendees=" + bbb["users"] + "|"
+        statusline += "numWithVideo=" + bbb["videos"] + " "
+        statusline += "[" + bbb["hostname"] + " M:" + bbb["meetings"] + " "
+        statusline += "Att:" + bbb["users"] + " "
+        statusline += "Vid:" + bbb["videos"] + "]"
+    
+    if bbb["state"] == "disabled" and bbb["status"] == "online":
+        statusline  = str(checkstate) + " " + "BBB_" + bbb["hostname"] + " "
+        statusline += "numMeetings=" + bbb["meetings"] + "|"
+        statusline += "numAttendees=" + bbb["users"] + "|"
+        statusline += "numWithVideo=" + bbb["videos"] + " "
+        statusline += "****DISABLED IN SCALELITE**** [" + bbb["hostname"] + " M:" + bbb["meetings"] + " "
+        statusline += "Att:" + bbb["users"] + " "
+        statusline += "Vid:" + bbb["videos"] + "]"
+    
+    if bbb["state"] == "enabled" and bbb["status"] == "offline":
+        checkstate = 2
+        statusline  = str(checkstate) + " " + "BBB_" + bbb["hostname"] + " "
+        statusline += "numMeetings=0|"
+        statusline += "numAttendees=0|"
+        statusline += "numWithVideo=0 "
+        statusline += "****ENABLED BUT OFFLINE****" 
+    
+    if bbb["state"] == "disabled" and bbb["status"] == "offline":
+        checkstate = 1
+        statusline  = str(checkstate) + " " + "BBB_" + bbb["hostname"] + " "
+        statusline += "numMeetings=0|"
+        statusline += "numAttendees=0|"
+        statusline += "numWithVideo=0 "
+        statusline += "****DISABLED IN SCALELITE AND OFFLINE****" 
+
+    totalMeetings += int(bbb["meetings"])
+    totalAttendees += int(bbb["users"])
+    totalVideousers += int(bbb["videos"])
+
+    return statusline
+
+
+
+# Global metrics
+totalMeetings = 0
+totalAttendees = 0
+totalVideousers = 0
+
+allservers = getStatus()
+
+for bbb in allservers:
+    print(generateCheckLine(bbb))
+
+
+statusline  = "0 BBBSCL_" + socket.gethostname() + " "
+statusline += "numMeetings=" + str(totalMeetings) + "|"
+statusline += "numAttendees=" + str(totalAttendees) + "|"
+statusline += "numWithVideo=" + str(totalVideousers) + " "
+statusline += "[scale001 totals "
+statusline += "M:" + str(totalMeetings) + " "
+statusline += "Att:" + str(totalAttendees) + " "
+statusline += "Vid:" + str(totalVideousers) + "]"
+
+print(statusline)
+overalltext  = "0 BBB_Overall_Attendees count="+str(totalAttendees) + ";200;500 "
+overalltext += str(totalAttendees) 
+print(overalltext)
diff --git a/checkmk/debian/checkbbb.sls b/checkmk/debian/checkbbb.sls
new file mode 100644
index 0000000..084359a
--- /dev/null
+++ b/checkmk/debian/checkbbb.sls
@@ -0,0 +1,7 @@
+hsh_checkmk_install_checkbbb_plugin:
+  file.managed:
+    - name: /usr/lib/check_mk_agent/plugins/checkbbb.py
+    - source: salt://checkmk/custom-files/plugins/checkbbb.py
+    - user: root
+    - group: root
+    - mode: 755
-- 
GitLab