a1 - test scripts
parent
e55cc0a04f
commit
d526848ac9
|
@ -0,0 +1,2 @@
|
|||
/config/config.yaml
|
||||
/test.sh
|
|
@ -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
|
|
@ -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<indent; i++) {vn=(vn)(vname[i])("_")}
|
||||
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
|
||||
}
|
||||
}'
|
||||
}
|
||||
|
||||
eval $(parse_yaml ./config/config.yaml "CONF_")
|
|
@ -0,0 +1,12 @@
|
|||
let express = require('express');
|
||||
|
||||
let app = express();
|
||||
var xmlparser = require('express-xml-bodyparser');
|
||||
app.use(xmlparser());
|
||||
|
||||
app.all('/collect',(req,res)=>{
|
||||
console.log(req);
|
||||
console.dir(req.body.monit.services[0]);
|
||||
});
|
||||
|
||||
app.listen(8081);
|
|
@ -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}
|
|
@ -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!")
|
||||
|
|
@ -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)
|
||||
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
|
@ -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'
|
|
@ -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
|
Loading…
Reference in New Issue