From e2fc0433de38c322ce46ad250bc0f0f03e7710c8 Mon Sep 17 00:00:00 2001 From: Cullum Smith Date: Thu, 24 Oct 2024 06:43:08 -0400 Subject: add icinga --- .../local/etc/icinga2/api-users.conf.icinga_server | 4 + .../features-available/icingadb.conf.icinga_server | 3 + .../local/etc/icingadb/config.yml.icinga_server | 10 + .../icingaweb2/authentication.ini.icinga_server | 10 + .../local/etc/icingaweb2/config.ini.icinga_server | 10 + .../local/etc/icingaweb2/groups.ini.icinga_server | 11 ++ .../icingadb/commandtransports.ini.icinga_server | 6 + .../modules/icingadb/config.ini.icinga_server | 5 + .../modules/icingadb/redis.ini.icinga_server | 3 + .../etc/icingaweb2/resources.ini.icinga_server | 28 +++ .../local/etc/icingaweb2/roles.ini.icinga_server | 12 ++ .../usr/local/etc/nginx/vhosts.conf.icinga_server | 33 ++++ .../etc/php-fpm.d/icingaweb.conf.icinga_server | 20 ++ .../local/etc/poudriere.d/pkglist.pkg_repository | 4 + files/usr/local/etc/redis.conf.icinga_server | 72 ++++++++ scripts/hostclass/bitwarden_server | 7 +- scripts/hostclass/dav_server | 8 +- scripts/hostclass/icinga_server | 203 +++++++++++++++++++++ scripts/hostclass/idm_server/10-slapd | 4 +- scripts/hostclass/idm_server/90-idm | 19 +- scripts/hostclass/postgresql_server | 21 ++- scripts/hostclass/ttrss_server | 7 +- vars/hostclass/icinga_server | 5 + vars/hostname/icinga1 | 3 + 24 files changed, 498 insertions(+), 10 deletions(-) create mode 100644 files/usr/local/etc/icinga2/api-users.conf.icinga_server create mode 100644 files/usr/local/etc/icinga2/features-available/icingadb.conf.icinga_server create mode 100644 files/usr/local/etc/icingadb/config.yml.icinga_server create mode 100644 files/usr/local/etc/icingaweb2/authentication.ini.icinga_server create mode 100644 files/usr/local/etc/icingaweb2/config.ini.icinga_server create mode 100644 files/usr/local/etc/icingaweb2/groups.ini.icinga_server create mode 100644 files/usr/local/etc/icingaweb2/modules/icingadb/commandtransports.ini.icinga_server create mode 100644 files/usr/local/etc/icingaweb2/modules/icingadb/config.ini.icinga_server create mode 100644 files/usr/local/etc/icingaweb2/modules/icingadb/redis.ini.icinga_server create mode 100644 files/usr/local/etc/icingaweb2/resources.ini.icinga_server create mode 100644 files/usr/local/etc/icingaweb2/roles.ini.icinga_server create mode 100644 files/usr/local/etc/nginx/vhosts.conf.icinga_server create mode 100644 files/usr/local/etc/php-fpm.d/icingaweb.conf.icinga_server create mode 100644 files/usr/local/etc/redis.conf.icinga_server create mode 100644 scripts/hostclass/icinga_server create mode 100644 vars/hostclass/icinga_server create mode 100644 vars/hostname/icinga1 diff --git a/files/usr/local/etc/icinga2/api-users.conf.icinga_server b/files/usr/local/etc/icinga2/api-users.conf.icinga_server new file mode 100644 index 0000000..6ee26c2 --- /dev/null +++ b/files/usr/local/etc/icinga2/api-users.conf.icinga_server @@ -0,0 +1,4 @@ +object ApiUser "${icingaweb_api_username}" { + password = "${icingaweb_api_password}" + permissions = [ "status/query", "actions/*", "objects/modify/*", "objects/query/*" ] +} diff --git a/files/usr/local/etc/icinga2/features-available/icingadb.conf.icinga_server b/files/usr/local/etc/icinga2/features-available/icingadb.conf.icinga_server new file mode 100644 index 0000000..6fda495 --- /dev/null +++ b/files/usr/local/etc/icinga2/features-available/icingadb.conf.icinga_server @@ -0,0 +1,3 @@ +object IcingaDB "icingadb" { + path = "${redis_sock}" +} diff --git a/files/usr/local/etc/icingadb/config.yml.icinga_server b/files/usr/local/etc/icingadb/config.yml.icinga_server new file mode 100644 index 0000000..e30d81c --- /dev/null +++ b/files/usr/local/etc/icingadb/config.yml.icinga_server @@ -0,0 +1,10 @@ +database: + type: pgsql + host: ${icinga_dbhost} + user: ${icinga_username} + password: ${icinga_password} + database: ${icinga_dbname} + tls: true + +redis: + host: ${redis_sock} diff --git a/files/usr/local/etc/icingaweb2/authentication.ini.icinga_server b/files/usr/local/etc/icingaweb2/authentication.ini.icinga_server new file mode 100644 index 0000000..52ed21d --- /dev/null +++ b/files/usr/local/etc/icingaweb2/authentication.ini.icinga_server @@ -0,0 +1,10 @@ +[icingaweb2] +backend = "ldap" +resource = "icingaweb_ldap" +base_dn = "${users_basedn}" +user_class = "inetOrgPerson" +user_name_attribute = "uid" +filter = "memberOf=cn=${icingaweb_access_role},${roles_basedn}" + +[autologin] +backend = external diff --git a/files/usr/local/etc/icingaweb2/config.ini.icinga_server b/files/usr/local/etc/icingaweb2/config.ini.icinga_server new file mode 100644 index 0000000..8c05a5f --- /dev/null +++ b/files/usr/local/etc/icingaweb2/config.ini.icinga_server @@ -0,0 +1,10 @@ +[global] +show_stacktraces = "0" +show_application_state_messages = "1" +config_resource = "icingaweb_db" + +[logging] +log = "syslog" +level = "INFO" +application = "icingaweb2" +facility = "user" diff --git a/files/usr/local/etc/icingaweb2/groups.ini.icinga_server b/files/usr/local/etc/icingaweb2/groups.ini.icinga_server new file mode 100644 index 0000000..87da799 --- /dev/null +++ b/files/usr/local/etc/icingaweb2/groups.ini.icinga_server @@ -0,0 +1,11 @@ +[icingaweb2] +backend = "ldap" +resource = "icingaweb_ldap" +user_backend = "icingaweb2" +user_class = "inetOrgPerson" +user_name_attribute = "uid" +user_base_dn = "${users_basedn}" +base_dn = "${groups_basedn}" +group_class = "groupOfMembers" +group_member_attribute = "member" +group_name_attribute = "cn" diff --git a/files/usr/local/etc/icingaweb2/modules/icingadb/commandtransports.ini.icinga_server b/files/usr/local/etc/icingaweb2/modules/icingadb/commandtransports.ini.icinga_server new file mode 100644 index 0000000..990e08a --- /dev/null +++ b/files/usr/local/etc/icingaweb2/modules/icingadb/commandtransports.ini.icinga_server @@ -0,0 +1,6 @@ +[icinga2] +skip_validation = "0" +transport = "api" +port = "${icinga_port}" +username = "${icingaweb_api_username}" +password = ${icingaweb_api_password}" diff --git a/files/usr/local/etc/icingaweb2/modules/icingadb/config.ini.icinga_server b/files/usr/local/etc/icingaweb2/modules/icingadb/config.ini.icinga_server new file mode 100644 index 0000000..7c19f9f --- /dev/null +++ b/files/usr/local/etc/icingaweb2/modules/icingadb/config.ini.icinga_server @@ -0,0 +1,5 @@ +[icingadb] +resource = "icingadb" + +[redis] +tls = "0" diff --git a/files/usr/local/etc/icingaweb2/modules/icingadb/redis.ini.icinga_server b/files/usr/local/etc/icingaweb2/modules/icingadb/redis.ini.icinga_server new file mode 100644 index 0000000..0064b7e --- /dev/null +++ b/files/usr/local/etc/icingaweb2/modules/icingadb/redis.ini.icinga_server @@ -0,0 +1,3 @@ +[redis1] +host = "localhost" +port = "${redis_port}" diff --git a/files/usr/local/etc/icingaweb2/resources.ini.icinga_server b/files/usr/local/etc/icingaweb2/resources.ini.icinga_server new file mode 100644 index 0000000..0400b1e --- /dev/null +++ b/files/usr/local/etc/icingaweb2/resources.ini.icinga_server @@ -0,0 +1,28 @@ +[icingaweb_db] +type = "db" +db = "pgsql" +host = "${icingaweb_dbhost}" +dbname = "${icingaweb_dbname}" +username = "${icinga_username}" +password = "" +port = "5432" +use_ssl = "0" + +[icingaweb_ldap] +type = "ldap" +hostname = "${ldap_hosts}" +port = "389" +encryption = "starttls" +bind_dn = "${icinga_dn}" +bind_pw = "${icinga_password}" +root_dn = "${accounts_basedn}" + +[icingadb] +type = "db" +db = "pgsql" +host = "${icinga_dbhost}" +dbname = "${icinga_dbname}" +username = "${icinga_username}" +password = "" +port = "5432" +use_ssl = "0" diff --git a/files/usr/local/etc/icingaweb2/roles.ini.icinga_server b/files/usr/local/etc/icingaweb2/roles.ini.icinga_server new file mode 100644 index 0000000..6e20e8a --- /dev/null +++ b/files/usr/local/etc/icingaweb2/roles.ini.icinga_server @@ -0,0 +1,12 @@ +[Administrators] +$(if [ -n "$icingaweb_admin_groups" ]; then +cat < /usr/local/etc/php-fpm.d/www.conf + +# Copy TLS certificate for nginx. +install_certificate nginx "$icingaweb_https_cert" +install_certificate_key nginx "$icingaweb_https_key" + +# Enable and start daemons. +sysrc -v \ + nginx_enable=YES \ + php_fpm_enable=YES \ + redis_enable=YES \ + icingadb_enable=YES \ + icinga2_enable=YES +service nginx restart +service php_fpm restart +service redis restart +service icingadb restart > /dev/null 2>&1 < /dev/null || die 'failed to start icingadb' +service icinga2 restart + +# Create access role. +ldap_add "cn=${icingaweb_access_role},${roles_basedn}" < /dev/null 2>&1 < /dev/null || die 'failed to start postgresql' # Create boxconf admin user. -psql --quiet --no-align --echo-all --tuples-only --no-password --username=postgres --dbname=postgres -c \ +postgres_psql -c \ "DO \$$ BEGIN @@ -87,3 +101,6 @@ BEGIN END IF; END \$$" + +# Load citext extension (required by icingadb) +postgres_psql -c 'create extension if not exists citext;' diff --git a/scripts/hostclass/ttrss_server b/scripts/hostclass/ttrss_server index 1a2104a..fc6fffd 100644 --- a/scripts/hostclass/ttrss_server +++ b/scripts/hostclass/ttrss_server @@ -8,6 +8,7 @@ : ${ttrss_admin_role:='ttrss-admin'} : ${ttrss_mail_from:="ttrss-noreply@${email_domain}"} +ttrss_dn="uid=${ttrss_username},${robots_basedn}" ttrss_https_cert="${nginx_conf_dir}/ttrss.crt" ttrss_https_key="${nginx_conf_dir}/ttrss.key" ttrss_repo='https://git.tt-rss.org/fox/tt-rss.git/' @@ -49,7 +50,11 @@ pkg install -y \ php${php_version}-zip # Create ttrss principal and keytab. -add_principal -nokey -x "containerdn=${robots_basedn}" "$ttrss_username" +ldap_add "$ttrss_dn" <