Commit 6764e5a2 authored by ulif's avatar ulif 🐻

Add role to setup munin-node monitoring.

parent 48b4bd92
munin_server_ipv4: ""
munin_server_ipv6: ""
#!/usr/bin/python3
#
# bbb.py
# Frank Schiebel frank@linuxmuster.net
# Adapted for munin by ulif <ulif@riseup.net>
# GPL v3
#
import sys
import socket
import hashlib
import requests
import subprocess
from collections import defaultdict
from xml.dom.minidom import parse, parseString
def get_api_checksum():
"""Get API Secret
cf. https://docs.bigbluebutton.org/dev/api.html
"""
output = subprocess.check_output(['bbb-conf', '--secret']).decode('utf-8')
secret = [x.strip() for x in output.split('\n') if 'Secret: ' in x][0].split(" ")[-1]
qstringwithsecret = "getMeetings" + secret
return hashlib.sha1(qstringwithsecret.encode('utf-8')).hexdigest()
def get_meeting_data(checksum):
"""Request current traffic data
from BBB via XML API.
"""
fqdn = socket.getfqdn()
full_query_uri = "https://%s/bigbluebutton/api/getMeetings?checksum=%s" % (fqdn, checksum)
result = requests.get(full_query_uri)
return result.status_code, result.text
(status, xml) = get_meeting_data(get_api_checksum())
numMeetings = 0
numAttendees = 0
numWithVideo = 0
numWithVoice = 0
numListeners = 0
if status != 200:
print("HTTP return code was not 200/OK")
sys.exit(-1)
meetingdata = parseString(xml)
returncode=meetingdata.getElementsByTagName("returncode")[0]
returncode=returncode.firstChild.wholeText
if returncode != "SUCCESS":
print("API returncode was not SUCCESS")
sys.exit(-1)
# get numbers from active meetings
meetings=meetingdata.getElementsByTagName("meeting")
for m in meetings:
p = m.getElementsByTagName("bbb-origin-server-name")[0]
numMeetings += 1
p = m.getElementsByTagName("participantCount")[0]
numAttendees += int(p.firstChild.wholeText)
p = m.getElementsByTagName("listenerCount")[0]
numListeners += int(p.firstChild.wholeText)
p = m.getElementsByTagName("voiceParticipantCount")[0]
numWithVoice += int(p.firstChild.wholeText)
p = m.getElementsByTagName("videoCount")[0]
numWithVideo += int(p.firstChild.wholeText)
if "autoconf" in sys.argv:
print("yes")
sys.exit(0)
elif "config" in sys.argv:
print("graph_order attendees listeners voice video meetings ")
print("graph_title BigBlueButton conferences")
print("graph_args --base 1000 -l 0")
print("graph_category system")
print("attendees.label attendees")
print("attendees.type DERIVE")
print("attendees.info Number of attendees")
print("attendees.draw AREA")
print("meetings.label meetings")
print("meetings.type DERIVE")
print("meetings.info Number of active conferences")
print("video.label video")
print("video.type DERIVE")
print("video.info Number of video streams")
print("video.draw STACK")
print("voice.label voice")
print("voice.type DERIVE")
print("voice.info Number of voice streams")
print("voice.draw STACK")
print("listeners.label listeners")
print("listeners.type DERIVE")
print("listeners.info Number of listening attendees")
print("listeners.draw STACK")
sys.exit(0)
print("meetings.value %s" % numMeetings)
print("attendees.value %s" % numAttendees)
print("video.value %s" % numWithVideo)
print("voice.value %s" % numWithVoice)
print("listeners.value %s" % numListeners)
sys.exit(0)
[Munin Node]
title=Munin Node
description=Daemon gathering system metrics
ports=4949/tcp
- name: restart munin_node
service: name=munin-node state=restarted
# Enable monitoring with munin
- name: install packages for monitoring
apt:
name:
- smartmontools
- munin-node
state: latest
- name: check if ufw rules dir exists
stat:
path: /etc/ufw/applications.d
register: ufw_dir
- name: Copy ufw rules to target
copy:
src: files/munin_node.ufw
dest: /etc/ufw/applications.d/munin-node
owner: root
group: root
mode: 0644
when: ufw_dir.stat.exists == true
# in case there is no munin server ip defines, we allow access from everywhere
- name: allow munin server to access node in ufw (all IPs allowed)
ufw:
rule: allow
name: "Munin Node"
state: enabled
when: ufw_dir.stat.exists == true and not munin_server_ipv4 and not munin_server_ipv6
- name: allow munin server to access node through ufw (certain server, ipv4)
ufw:
rule: allow
proto: tcp
src: "{{ munin_server_ipv4 }}"
port: "4949"
when: munin_server_ipv4 | length
- name: allow munin server to access node through ufw (certain server, ipv6)
ufw:
rule: allow
proto: tcp
src: "{{ munin_server_ipv6 }}"
port: "4949"
when: munin_server_ipv6 | length
- name: Copy bbb.py to /etc/munin/plugins/bbb on target
copy:
src: bbb.py
dest: /etc/munin/plugins/bbb
owner: root
group: root
mode: 0755
notify: restart munin_node
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment