diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1115446 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/config/config.yaml +/test.sh \ No newline at end of file diff --git a/config/config.example.yaml b/config/config.example.yaml new file mode 100644 index 0000000..7ba2ad9 --- /dev/null +++ b/config/config.example.yaml @@ -0,0 +1,17 @@ +global: + debug: yes + discord: + webhookurl: https://discord.com/api/webhooks/ + network: + interface: eth0 + dhcp: yes + filesystem: + - hdd: / + max: 20 + warn: 15 + - hdd: /mnt/hdd2 + max: 3570 + warn: 3000 + - hdd: /mnt/hdd3 + warn: 18000 + max: 20000 diff --git a/helper/parse_yaml.sh b/helper/parse_yaml.sh new file mode 100644 index 0000000..65cb6fd --- /dev/null +++ b/helper/parse_yaml.sh @@ -0,0 +1,19 @@ +#!/bin/sh +function parse_yaml { + local prefix=$2 + local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034') + sed -ne "s|^\($s\):|\1|" \ + -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \ + -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 | + awk -F$fs '{ + indent = length($1)/2; + vname[indent] = $2; + for (i in vname) {if (i > indent) {delete vname[i]}} + if (length($3) > 0) { + vn=""; for (i=0; i{ + console.log(req); + console.dir(req.body.monit.services[0]); +}); + +app.listen(8081); diff --git a/runner.sh b/runner.sh new file mode 100644 index 0000000..19da6e6 --- /dev/null +++ b/runner.sh @@ -0,0 +1,7 @@ +#!/bin/sh +source ./helper/parse_yaml.sh + +py=/usr/bin/python3 + + +${py} ./scripts/DHCP.py ${CONF_global_network_interface} ${CONF_global_network_dhcp} \ No newline at end of file diff --git a/scripts/DHCP.py b/scripts/DHCP.py new file mode 100644 index 0000000..8e1d60c --- /dev/null +++ b/scripts/DHCP.py @@ -0,0 +1,26 @@ +#!/usr/bin/python3 + +import sys +import re +import subprocess + +from lib import bcolor + +bcolors = bcolor.bcolors + +regex = r"inet ((([0-9]{1,3}.){4})(\/){0,1}([0-9]{0,2}))" + +INTERFACE=sys.argv[1] +DHCP=sys.argv[2] +RET="" +INTERFACE_DUMP = subprocess.run(["ip", "a" ,"show","dev",INTERFACE],stdout=subprocess.PIPE, text=True) +matches = re.search(regex, INTERFACE_DUMP.stdout) + +if DHCP == "yes": + if matches: + print(bcolors.BOLD + bcolors.OKCYAN+"[CONFIG - NETWORK]"+bcolors.ENDC+" found IP address on "+INTERFACE+".") + else: + print(bcolors.BOLD + bcolors.FAIL+"[CONFIG - NETWORK]"+bcolors.ENDC+" got no IP address, run dhclient on "+INTERFACE+"!") +else: + print(bcolors.BOLD + bcolors.WARNING+"[CONFIG - NETWORK]"+bcolors.ENDC+" no DHCP active in configuration!") + diff --git a/scripts/FILESYSTEM.py b/scripts/FILESYSTEM.py new file mode 100644 index 0000000..08acc44 --- /dev/null +++ b/scripts/FILESYSTEM.py @@ -0,0 +1,32 @@ +import sys +import re +import subprocess +import yaml +import shutil +from lib import bcolor + +bcolors = bcolor.bcolors + + +with open('./config/config.yaml') as f: + + data = yaml.load(f, Loader=yaml.FullLoader) + hhds = data["global"]["filesystem"] + for hddNum in range(0, len(hhds)): + total, used, free = shutil.disk_usage(hhds[hddNum]["hdd"]) + hdd_total = (total // (2**30)) + hdd_used = (used // (2**30)) + hdd_free = (free // (2**30)) + print(bcolors.BOLD + bcolors.HEADER+"⸢-------------------------------------------------------------------------"+bcolors.ENDC+"") + print(bcolors.BOLD + bcolors.HEADER+"⸠ [FILESYSTEM CHECK]"+bcolors.ENDC+" Filesystem: %s " % hhds[hddNum]["hdd"]) + if hhds[hddNum]["warn"] < hdd_used: + print(bcolors.BOLD + bcolors.FAIL+"⸠ [FILESYSTEM CHECK]"+bcolors.ENDC+" Free: %d GiB" % hdd_free) + print(bcolors.BOLD + bcolors.FAIL+"⸠ [FILESYSTEM CHECK]"+bcolors.ENDC+" Used: %d GiB" % hdd_used) + print(bcolors.BOLD + bcolors.FAIL+"⸤ [FILESYSTEM CHECK]"+bcolors.ENDC+" Total: %d GiB" % hdd_total) + else: + print(bcolors.BOLD + bcolors.OKGREEN+"⸠ [FILESYSTEM CHECK]"+bcolors.ENDC+" Free: %d GiB" % hdd_free) + print(bcolors.BOLD + bcolors.OKGREEN+"⸠ [FILESYSTEM CHECK]"+bcolors.ENDC+" Used: %d GiB" % hdd_used) + print(bcolors.BOLD + bcolors.OKGREEN+"⸤ [FILESYSTEM CHECK]"+bcolors.ENDC+" Total: %d GiB" % hdd_total) + + + \ No newline at end of file diff --git a/scripts/lib/__init__.py b/scripts/lib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/scripts/lib/__pycache__/__init__.cpython-37.pyc b/scripts/lib/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..d384015 Binary files /dev/null and b/scripts/lib/__pycache__/__init__.cpython-37.pyc differ diff --git a/scripts/lib/__pycache__/bcolor.cpython-37.pyc b/scripts/lib/__pycache__/bcolor.cpython-37.pyc new file mode 100644 index 0000000..f5945a3 Binary files /dev/null and b/scripts/lib/__pycache__/bcolor.cpython-37.pyc differ diff --git a/scripts/lib/bcolor.py b/scripts/lib/bcolor.py new file mode 100644 index 0000000..03d4251 --- /dev/null +++ b/scripts/lib/bcolor.py @@ -0,0 +1,11 @@ +#!/usr/bin/python3 +class bcolors: + HEADER = '\033[95m' + OKBLUE = '\033[94m' + OKCYAN = '\033[96m' + OKGREEN = '\033[92m' + WARNING = '\033[93m' + FAIL = '\033[91m' + ENDC = '\033[0m' + BOLD = '\033[1m' + UNDERLINE = '\033[4m' \ No newline at end of file diff --git a/scripts/notify.rb b/scripts/notify.rb new file mode 100644 index 0000000..0929bf7 --- /dev/null +++ b/scripts/notify.rb @@ -0,0 +1,18 @@ +#!/usr/bin/ruby + +require 'net/https' +require 'yaml' +require 'json' + +readme_doc = YAML::load( File.open( './config/config.yaml' ) ) +puts readme_doc + +uri = URI.parse(readme_doc["global"]["discord"]["webhookurl"]) +http = Net::HTTP.new(uri.host, uri.port) +http.use_ssl = true +request = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' => 'application/json'}) +request.body = { + "content" => "[#{ENV['MONIT_HOST']}] #{ENV['MONIT_SERVICE']} - #{ENV['MONIT_DESCRIPTION']}" +}.to_json +response = http.request(request) +puts response.body \ No newline at end of file