diff --git a/.gitignore b/.gitignore index acabf55..2728222 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,10 @@ +# Generated files roles/Node/files/*-vm.service roles/Nazara/files/dns roles/Nazara/files/dhcp roles/Node/files/vm-definitions/** roles/ShadowArch/files/mirrorlist +roles/Sharingan/files/monit/checks/availability roles/Foundation/files/custom/public/img/** venv/** **/pkg/** diff --git a/bin/deploy-role b/bin/deploy-role index 72b3663..9fa52e3 100755 --- a/bin/deploy-role +++ b/bin/deploy-role @@ -33,8 +33,7 @@ done # Get the targetgroup targetgroup="$2" if [ -z "$targetgroup" ]; then - echo Need a group - exit 2 + targetgroup="$role" # Deploy a role to the server named for that function fi # Allow an inventory override diff --git a/bin/generate-mirrorlist b/bin/generate-mirrorlist old mode 100644 new mode 100755 diff --git a/bin/generate-monitoring.py b/bin/generate-monitoring.py new file mode 100755 index 0000000..1761e0f --- /dev/null +++ b/bin/generate-monitoring.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 +# File: generate-pihole-dns-dhcp.py +# +# Description: This file generates the DNS and DHCP files for pihole. +# +# Package: AniNIX/Ubiqtorate +# Copyright: WTFPL +# +# Author: DarkFeather + +import os +import subprocess +import sys +import yaml + +rolepath='../roles/Sharingan/files' +monfilepath=rolepath+"/monit/checks/availability" + +def WriteMonitoringEntry(content,hosttype,hostclass): + ### Create the ping-based monitoring entry + # param content: the yaml content to parse + # param hosttype: managed or unmanaged + # param hostclass: the type of host as classified in the yaml + global monfile + + with open(monfilepath,'a') as monfile: + + # Write host entries + for host in content['all']['children'][hosttype]['children'][hostclass]['hosts']: + try: + hostname= host + '.' + content['all']['vars']['replica_domain'] + monfile.write('check program ' + host + '_ping_mon with path "/usr/lib/monitoring-plugins/check_ping -H ' + hostname + ' -w 100,50% -c 1000,100% -p 3 -t 60 -4"\n') + monfile.write(' if status != 0 for 3 times within 5 cycles then exec "/etc/monit.d/scripts/critical ' + hostname + ' is not online."\n\n') + except: + print(host + ' is not complete for monitoring.') + +def WriteSSHMonitoringEntry(content,hosttype,hostclass): + ### Create the ping-based monitoring entry + # param content: the yaml content to parse + # param hosttype: managed or unmanaged + # param hostclass: the type of host as classified in the yaml + global monfile + + with open(monfilepath,'a') as monfile: + + # Write host entries + for host in content['all']['children'][hosttype]['children'][hostclass]['hosts']: + try: + hostname= host + '.' + content['all']['vars']['replica_domain'] + monfile.write('check program ' + host + '_ssh_mon with path "/usr/lib/monitoring-plugins/check_ssh -H ' + hostname + '"\n') + monfile.write(' if status != 0 for 3 times within 5 cycles then exec "/etc/monit.d/scripts/critical ' + hostname + ' is not responding to SSH."\n\n') + except: + print(host + ' is not complete for monitoring.') + +def GenerateFiles(file): + ### Open the file and parse it + # param file: the file to work on + global monfilepath + + if not os.path.isdir(rolepath): + os.mkdir(rolepath) + + # Parse the yaml + with open(file, 'r') as stream: + content = yaml.safe_load(stream) + + if os.path.isfile(monfilepath): os.remove(monfilepath) + + # Add DNS entries for each host + hosttype = 'managed' + for hostclass in ['physical','virtual','geth_hubs']: + WriteMonitoringEntry(content,hosttype,hostclass) + WriteSSHMonitoringEntry(content,hosttype,hostclass) + hosttype = 'unmanaged' + for hostclass in ['ovas','appliances']: + WriteMonitoringEntry(content,hosttype,hostclass) + +if __name__ == '__main__': + if len(sys.argv) != 2: + print("You need to supply an inventory file.") + sys.exit(1) + GenerateFiles(sys.argv[1]) + sys.exit(0) diff --git a/bin/generate-pihole-dns-dhcp.py b/bin/generate-pihole-dns-dhcp.py index d8ebd1c..e215379 100755 --- a/bin/generate-pihole-dns-dhcp.py +++ b/bin/generate-pihole-dns-dhcp.py @@ -74,7 +74,7 @@ def GenerateFiles(file): WriteDNSEntry(content,hosttype,hostclass) WriteDHCPEntry(content,hosttype,hostclass) hosttype = 'unmanaged' - for hostclass in ['ovas','appliances','iot']: + for hostclass in ['ovas','test_ovas','appliances','adhoc_appliances','iot']: WriteDNSEntry(content,hosttype,hostclass) WriteDHCPEntry(content,hosttype,hostclass) diff --git a/bin/generate-systemd-vms.py b/bin/generate-systemd-vms.py index 370a897..f1ba1b6 100755 --- a/bin/generate-systemd-vms.py +++ b/bin/generate-systemd-vms.py @@ -84,8 +84,8 @@ def GenerateFiles(file): # Add service files for each host WriteVMFile(content,'managed','virtual') - WriteVMFile(content,'unmanaged','ovas') - #WriteVMFile(content,'unmanaged','appliances') + WriteVMFile(content,'unmanaged','ovas', + WriteVMFile(content,'unmanaged','test_ovas') if __name__ == '__main__': if len(sys.argv) != 2: diff --git a/examples/msn0.yml b/examples/msn0.yml index 9135aa4..14e3db6 100644 --- a/examples/msn0.yml +++ b/examples/msn0.yml @@ -71,6 +71,8 @@ all: siem: true disks: - '-drive format=raw,index=0,media=disk,file=/dev/sdb' + # On hold because of https://aninix.net/DarkFeather/MSN0/issues/6 + holdpkg: "elasticsearch graylog mongodb44-bin mongodb-tools-bin" DarkNet: ipinterface: ens3 ip: 10.0.1.17 @@ -110,17 +112,9 @@ all: rotate: 90 unmanaged: children: + # Both OVA groups are in the same subnet -- test_ovas aren't monitored ovas: # 10.0.1.48/28 hosts: - TDS-Jump: - ip: 10.0.1.48 - mac: 00:15:5d:01:02:08 - cores: 2 - memory: 2 - vnc: 4 - bridge: br0 - disks: - - '-drive format=qcow2,l2-cache-size=8M,file=/srv/maat/vm/TDSJump.qcow2' Geth: ip: 10.0.1.49 mac: DE:8B:9E:19:55:1E @@ -131,6 +125,17 @@ all: uefi: true disks: - '-drive format=qcow2,l2-cache-size=8M,file=/srv/maat/vm/hassos_ova-5.13.qcow2' + test_ovas: # 10.0.1.48/28 + hosts: + TDS-Jump: + ip: 10.0.1.48 + mac: 00:15:5d:01:02:08 + cores: 2 + memory: 2 + vnc: 4 + bridge: br0 + disks: + - '-drive format=qcow2,l2-cache-size=8M,file=/srv/maat/vm/TDSJump.qcow2' DedNet: ip: 10.0.1.50 mac: 00:15:5d:01:02:09 @@ -181,11 +186,26 @@ all: vnc: 12 disks: - '-drive format=qcow2,l2-cache-size=8M,file=/srv/maat/vm/test3.qcow2' + # appliances are monitored -- adhoc_appliances are convenience only and not monitored. appliances: hosts: # 10.0.1.64/27 - Shadowfeed: + Shadowfeed: # Router must be at root ip: 10.0.1.1 mac: 2c:30:33:64:f4:03 + Print: # Print is excepted for legacy setup reasons before we laid out subnets. + ip: 10.0.1.6 + mac: 00:80:92:77:CE:E4 + Geth-Eyes: + ip: 10.0.1.68 + mac: 9C:A3:AA:33:A3:99 + "Core-Console": + ip: 10.0.1.74 + mac: 00:25:90:0D:82:5B + "Node0-Console": + ip: 10.0.1.75 + mac: 00:25:90:3E:C6:8C + adhoc_appliances: + hosts: # 10.0.1.64/27 DarkFeather: ip: 10.0.1.64 mac: D0:40:EF:D4:14:CF @@ -195,19 +215,13 @@ all: Games: ip: 10.0.1.66 mac: E0:BE:03:77:0E:88 - Print: - ip: 10.0.1.67 - mac: 00:80:92:77:CE:E4 - Geth-Eyes: - ip: 10.0.1.68 - mac: 9C:A3:AA:33:A3:99 LivingRoomTV: ip: 10.0.1.69 mac: 80:D2:1D:17:63:0E BedRoomTV: ip: 10.0.1.70 mac: 80:D2:1D:17:63:0F - TraingRoomTV: + TrainingRoomTV: ip: 10.0.1.71 mac: 80:D2:1D:17:63:10 Tachikoma: @@ -216,12 +230,6 @@ all: Dedsec: ip: 10.0.1.73 mac: 34:F6:4B:36:12:8F - "Core-Console": - ip: 10.0.1.74 - mac: 00:25:90:0D:82:5B - "Node0-Console": - ip: 10.0.1.75 - mac: 00:25:90:3E:C6:8C # dhcp build space: 10.0.1.224/27 iot: # 10.0.2.0/24 hosts: diff --git a/roles/Foundation/files/custom/templates/custom/footer.tmpl b/roles/Foundation/files/custom/templates/custom/footer.tmpl index 4c7ba98..bd4f5f0 100644 --- a/roles/Foundation/files/custom/templates/custom/footer.tmpl +++ b/roles/Foundation/files/custom/templates/custom/footer.tmpl @@ -13,7 +13,7 @@ _gaq.push(['_trackPageview']);