diff options
Diffstat (limited to 'monitoring')
| -rwxr-xr-x | monitoring/icinga-agent | 108 | ||||
| -rwxr-xr-x | monitoring/icinga-master | 120 |
2 files changed, 228 insertions, 0 deletions
diff --git a/monitoring/icinga-agent b/monitoring/icinga-agent new file mode 100755 index 0000000..328d65b --- /dev/null +++ b/monitoring/icinga-agent | |||
| @@ -0,0 +1,108 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | # | ||
| 3 | # Configirues an icinga2 agent (with on-demand csr signing) | ||
| 4 | |||
| 5 | icingauser="nagios" | ||
| 6 | certdir="/etc/icinga2/pki" | ||
| 7 | api_certdir="/var/lib/icinga2/certs" | ||
| 8 | nodename="$(hostname)" | ||
| 9 | global_zone="director-global" | ||
| 10 | master_fqdn="" | ||
| 11 | |||
| 12 | # Install packages | ||
| 13 | apt install -y icinga2 monitoring-plugins monitoring-plugins-contrib | ||
| 14 | |||
| 15 | # Register with master via self-service API | ||
| 16 | apikey="" | ||
| 17 | displayname="" | ||
| 18 | # Not pretty but gets the job done | ||
| 19 | dev="$(ip link | grep ^2: | head -1 | cut -d':' -f 2 | tr -d ' ')" | ||
| 20 | ipv4="$(ip addr show $dev | grep "inet " | sed "s/^\s*//;s/\// /" | cut -d ' ' -f 2)" | ||
| 21 | ipv6="$(ip addr show $dev | grep "inet6 " | sed "s/^\s*//;s/\// /" | cut -d ' ' -f 2)" | ||
| 22 | |||
| 23 | result=$(curl -i "http://$master_fqdn/icingaweb2/director/self-service/register-host?name=$nodename&key=$apikey" \ | ||
| 24 | -H "Accept: application/json" \ | ||
| 25 | -X "POST" \ | ||
| 26 | -d "{\"display_name\":\"$displayname\",\"address\":\"$ipv4\",\"address6\":\"$ipv6\"}") | ||
| 27 | echo $result | grep -q error && \ | ||
| 28 | echo "error: unable to register with master (is the api key correct?)" && \ | ||
| 29 | exit 2 | ||
| 30 | |||
| 31 | |||
| 32 | # Initialize PKI with master | ||
| 33 | icinga2 pki new-cert \ | ||
| 34 | --cn "pbs.home.local" \ | ||
| 35 | --cert "$certdir/$nodename.crt" \ | ||
| 36 | --csr "$certdir/$nodename.csr" \ | ||
| 37 | --key "$certdir/$nodename.key" | ||
| 38 | |||
| 39 | |||
| 40 | icinga2 pki save-cert \ | ||
| 41 | --host "$master_fqdn" \ | ||
| 42 | --port 5665 \ | ||
| 43 | --key "$certdir/$nodename.key" \ | ||
| 44 | --trustedcert "$certdir/trusted-master.crt" | ||
| 45 | |||
| 46 | icinga2 pki request \ | ||
| 47 | --host "$master_fqdn" \ | ||
| 48 | --port 5665 \ | ||
| 49 | --key "$certdir/$nodename.key" \ | ||
| 50 | --cert "$certdir/$nodename.crt" \ | ||
| 51 | --trustedcert "$certdir/trusted-master.crt" \ | ||
| 52 | --ca "$certdir/ca.crt" | ||
| 53 | |||
| 54 | # Deploy config files | ||
| 55 | echo "include \"constants.conf\" | ||
| 56 | const NodeName = \"$nodename\" | ||
| 57 | include \"zones.conf\" | ||
| 58 | include \"features-enabled/*.conf\" | ||
| 59 | include <itl> | ||
| 60 | include <plugins> | ||
| 61 | include <plugins-contrib> | ||
| 62 | include <manubulon> | ||
| 63 | include <windows-plugins> | ||
| 64 | include <nscp>" > /etc/icinga2/icinga2.conf | ||
| 65 | |||
| 66 | echo "object Endpoint \"$nodename\" {} | ||
| 67 | object Zone \"$nodename\" { | ||
| 68 | parent = \"$master_fqdn\" | ||
| 69 | endpoints = [ \"$nodename\" ] | ||
| 70 | } | ||
| 71 | object Zone \"$master_fqdn\" { | ||
| 72 | endpoints = [ \"$master_fqdn\" ] | ||
| 73 | } | ||
| 74 | object Endpoint \"$master_fqdn\" { | ||
| 75 | host = \"$master_fqdn\" | ||
| 76 | } | ||
| 77 | object Zone \"$global_zone\" { | ||
| 78 | global = true | ||
| 79 | }" > /etc/icinga2/zones.conf | ||
| 80 | |||
| 81 | echo "object ApiListener \"api\" { | ||
| 82 | accept_commands = true | ||
| 83 | accept_config = true | ||
| 84 | }" > /etc/icinga2/features-available/api.conf | ||
| 85 | |||
| 86 | # Enable API | ||
| 87 | icinga2 feature enable api | ||
| 88 | mkdir -p $api_certdir | ||
| 89 | cp $certdir/$nodename.crt $certdir/$nodename.key $certdir/ca.crt $api_certdir/ | ||
| 90 | chown -R $icingauser:$icingauser $api_certdir/ | ||
| 91 | |||
| 92 | # Next step | ||
| 93 | echo " | ||
| 94 | |||
| 95 | NOW | ||
| 96 | |||
| 97 | Run the following on the Icinga master: | ||
| 98 | fpr=\"\$(icinga2 ca list | tail -1 | cut -d '|' -f 1)\" | ||
| 99 | icinga2 ca sign \$fpr | ||
| 100 | |||
| 101 | |||
| 102 | THEN | ||
| 103 | |||
| 104 | Restart icinga2 on the agent: | ||
| 105 | \"systemctl restart icinga2\" | ||
| 106 | |||
| 107 | " | ||
| 108 | |||
diff --git a/monitoring/icinga-master b/monitoring/icinga-master new file mode 100755 index 0000000..ed82bc5 --- /dev/null +++ b/monitoring/icinga-master | |||
| @@ -0,0 +1,120 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | # | ||
| 3 | # Configuration for an Iciniga2 master (with icingaweb2, director, and mysql backend) | ||
| 4 | |||
| 5 | ido_user="icinga2" | ||
| 6 | ido_password="changeme" | ||
| 7 | |||
| 8 | icingaweb2_user="icingaweb2" | ||
| 9 | icingaweb2_password="changeme" | ||
| 10 | |||
| 11 | director_user="director" | ||
| 12 | director_password="changeme" | ||
| 13 | |||
| 14 | admin_user="admin" | ||
| 15 | admin_password="changeme" | ||
| 16 | |||
| 17 | # Install packages | ||
| 18 | apt install -y incinga2 icingaweb2 icinga2-ido-mysql icingaweb2-module-director \ | ||
| 19 | monitoring-plugins monitoring-plugins-contrib | ||
| 20 | |||
| 21 | # Secure mysql | ||
| 22 | mysql_secure_installation | ||
| 23 | |||
| 24 | # Create primary monitoring database | ||
| 25 | mysql -u root -e "CREATE DATABASE icinga2; | ||
| 26 | GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE VIEW, INDEX, EXECUTE | ||
| 27 | ON icinga2.* TO '$ido_user'@'localhost' IDENTIFIED BY '$ido_password'; | ||
| 28 | FLUSH PRIVILEGES; " | ||
| 29 | mysql -u root icinga2 </usr/share/icinga2-ido-mysql/scheme/mysql.sql | ||
| 30 | echo "library \"db_ido_mysql\" | ||
| 31 | object IdoMysqlConnection \"ido-mysql\" { | ||
| 32 | user = \"$ido_user\", | ||
| 33 | password = \"$ido_password\", | ||
| 34 | host = \"localhost\", | ||
| 35 | databse = \"icinga2\" | ||
| 36 | }" > /etc/icinga2/features-available/ido-mysql.conf | ||
| 37 | icinga2 feature enable ido-mysql | ||
| 38 | |||
| 39 | # Create icingaweb2 database | ||
| 40 | mysql -u root -e "CREATE DATABASE icingaweb2; | ||
| 41 | GRANT ALL ON icingaweb2.* TO '$icingaweb2_user'@'localhost' | ||
| 42 | IDENTIFIED BY '$icingaweb2_password'; | ||
| 43 | FLUSH PRIVILEGES;" | ||
| 44 | mysql icingaweb2 </usr/share/icingaweb2/etc/scheme/mysql.schema.sql | ||
| 45 | # Create initial admin user to login to icingaweb2 | ||
| 46 | passhash="$(php -r "echo password_hash(\"$admin_password\", PASSWORD_DEFAULT);")" | ||
| 47 | mysql -u root -e "USE icingaweb2; | ||
| 48 | INSERT INTO icingaweb_user (name, active, password_hash) | ||
| 49 | VALUES (\"$admin_user\", 1, \"$passhash\"); | ||
| 50 | FLUSH PRIVILEGES; " | ||
| 51 | |||
| 52 | # Create director database | ||
| 53 | mysql -u root -e "CREATE DATABASE director CHARACTER SET 'utf8'; | ||
| 54 | GRANT ALL on director.* TO '$director_user'@'localhost' | ||
| 55 | IDENTIFIED BY '$director_password'; | ||
| 56 | FLUSH PRIVILEGES;" | ||
| 57 | icingacli module enable director | ||
| 58 | icingacli director migration run --verbose | ||
| 59 | |||
| 60 | # Setup API | ||
| 61 | icinga2 api setup | ||
| 62 | |||
| 63 | # Restart service | ||
| 64 | systemctl restart icinga2 | ||
| 65 | |||
| 66 | |||
| 67 | # -- Icingaweb2 Configuration -- | ||
| 68 | |||
| 69 | # Configure authentication | ||
| 70 | echo "[icingaweb2] | ||
| 71 | backend = \"db\" | ||
| 72 | resource = \"icingaweb2\" | ||
| 73 | " > /etc/icingaweb2/authentication.ini | ||
| 74 | |||
| 75 | # Configure resources | ||
| 76 | echo "[icinga2] | ||
| 77 | type = \"db\" | ||
| 78 | db = \"mysql\" | ||
| 79 | host \"localhost\" | ||
| 80 | port = \"\" | ||
| 81 | dbname = \"icinga2\" | ||
| 82 | username = \"$icinga2_user\" | ||
| 83 | password = \"$icinga2_password\" | ||
| 84 | charset = \"\" | ||
| 85 | use_ssl = \"0\" | ||
| 86 | |||
| 87 | [icingaweb2] | ||
| 88 | type = \"db\" | ||
| 89 | db = \"mysql\" | ||
| 90 | host \"localhost\" | ||
| 91 | port = \"\" | ||
| 92 | dbname = \"icingaweb2\" | ||
| 93 | username = \"$icingaweb2_user\" | ||
| 94 | password = \"$icingaweb2_password\" | ||
| 95 | charset = \"\" | ||
| 96 | use_ssl = \"0\" | ||
| 97 | |||
| 98 | [icingaweb2] | ||
| 99 | type = \"db\" | ||
| 100 | db = \"mysql\" | ||
| 101 | host \"localhost\" | ||
| 102 | port = \"\" | ||
| 103 | dbname = \"director\" | ||
| 104 | username = \"$director_user\" | ||
| 105 | password = \"$director_password\" | ||
| 106 | charset = \"utf8\" | ||
| 107 | use_ssl = \"0\" | ||
| 108 | " > /etc/icingaweb2/resources.ini | ||
| 109 | |||
| 110 | # Configure roles | ||
| 111 | echo "[admins] | ||
| 112 | users = \"$admin_user\" | ||
| 113 | permissions = \"*\" " > /etc/icingaweb2/roles.ini | ||
| 114 | |||
| 115 | # Configure director | ||
| 116 | echo "[db] | ||
| 117 | resource = \"director\" | ||
| 118 | " > /etc/icingaweb2/modules/director/config.ini | ||
| 119 | |||
| 120 | echo "NOW\nBrowse to http://$(hostname)/icingaweb2/ and login as $admin_user" | ||
