) { + chomp; + my @ret = split(/\s+/, $_); + push(@zpool, { + 'name' => $ret[0], + 'health' => $ret[-2], + 'size' => $ret[1], + 'alloc' => $ret[2], + 'free' => $ret[3] + }); + } + close(P); + my $rc = $?; + if ($rc != 0) { + &nagios_response("zpool list command failed (rc=$rc)", N_CRITICAL); + } +} + +sub get_status() +{ + my $storage = shift || "unknown"; + my $cat = 0; + my $res = {}; + local *P; + my $zpool_cmd = $EUID == 0 ? "zpool" : "sudo zpool"; + open(P, $zpool_cmd . " status $storage 2>&1 |") or &nagios_response("Could not find zpool command", N_CRITICAL); + while (
) { + chomp; + if ($_ =~ /^\s*([^\s]+):\s*(.*)$/) { + $cat = $1; + $res->{"$cat"} = (); + if ($2) { + push(@{$res->{"$cat"}}, $2); + } + } elsif ($cat && $_ =~ /^\s+(.+)$/) { + push(@{$res->{"$cat"}}, $1); + } + } + close(P); + my $rc = $?; + if ($rc != 0) { + &nagios_response("zpool status command failed (rc=$rc)", N_CRITICAL); + } + return $res; +} + +sub nagios_response() +{ + my $msg = shift || "Unknown"; + my $exit_status = shift; + if (!defined($exit_status)) { + $exit_status = N_CRITICAL; + } + printf("%s %s\n", N_MSG->[$exit_status], $msg); + exit($exit_status); +} + +sub main() { + + &get_pools(); + my $exit_status = N_OK; + my @out = (); + foreach my $pool (@zpool) { + if ($pool->{'health'} eq 'DEGRADED') { + $exit_status = N_WARNING; + my $extinfo = &get_status($pool->{'name'}); + my $scanned = 0; + my $total = 0; + my $speed = 0; + my $left = 0; + my $percent = 0; + my $resilvered = 0; + if (defined($extinfo->{'scan'})) { + foreach my $line (@{$extinfo->{'scan'}}) { + if ($line =~ /^\s*([^\s]+)\s+scanned out of\s+([^\s]+)\s+at\s+([^\s]+),\s*([^\s]+)\s+to go/) { + $scanned = $1; + $total = $2; + $speed = $3; + $left = $4; + } elsif ($line =~ /^\s*([^\s]+)\s+resilvered,\s*([^\s]+)\s+done/) { + $resilvered = $1; + $percent = $2; + } + } + } + if ($scanned && length($scanned) > 2) { + push(@out, sprintf("%s(RESILVER %s,%s,%s)", $pool->{'name'}, $percent, $speed, $left)); + } else { + push(@out, sprintf("%s(%s %s/%s)", $pool->{'name'}, $pool->{'health'}, $pool->{'alloc'}, $pool->{'size'})); + } + } elsif ($pool->{'health'} ne 'ONLINE') { + $exit_status = N_WARNING; + push(@out, sprintf("%s(%s %s/%s)", $pool->{'name'}, $pool->{'health'}, $pool->{'alloc'}, $pool->{'size'})); + } else { + push(@out, sprintf("%s(%s %s/%s)", $pool->{'name'}, $pool->{'health'}, $pool->{'alloc'}, $pool->{'size'})); + } + } + &nagios_response(join(",", @out), $exit_status); +} + +&main(); diff --git a/roles/pve/files/sudoers b/roles/pve/files/sudoers new file mode 100644 index 0000000..448fcd8 --- /dev/null +++ b/roles/pve/files/sudoers @@ -0,0 +1 @@ +nagios ALL=(root) NOPASSWD: /usr/bin/zpool,/usr/sbin/smartctl,/usr/lib/nagios/plugins/check_zfs.pl diff --git a/roles/pve/files/vhost.conf b/roles/pve/files/vhost.conf new file mode 100644 index 0000000..f536dc0 --- /dev/null +++ b/roles/pve/files/vhost.conf @@ -0,0 +1 @@ +options vhost max_mem_regions=512 diff --git a/roles/pve/handlers/main.yml b/roles/pve/handlers/main.yml new file mode 100644 index 0000000..c096c8e --- /dev/null +++ b/roles/pve/handlers/main.yml @@ -0,0 +1,8 @@ +- name: restart-nrpe + service: + name: nagios-nrpe-server + state: restarted +- name: restart-sysctl + service: + name: systemd-sysctl + state: restarted diff --git a/roles/pve/tasks/main.yml b/roles/pve/tasks/main.yml new file mode 100644 index 0000000..af048f9 --- /dev/null +++ b/roles/pve/tasks/main.yml @@ -0,0 +1,4 @@ +- import_tasks: nrpe.yml + tags: nrpe +- import_tasks: vhost.yml + tags: vhost diff --git a/roles/pve/tasks/nrpe.yml b/roles/pve/tasks/nrpe.yml new file mode 100644 index 0000000..e280c13 --- /dev/null +++ b/roles/pve/tasks/nrpe.yml @@ -0,0 +1,24 @@ +- name: Set NRPE PVE configuration + copy: + src: nrpe.cfg + dest: /etc/nagios/nrpe.d/95-pve.cfg + owner: root + group: root + mode: u=rw,g=r,o=r + notify: restart-nrpe +- name: Copy PVE NRPE plugins + copy: + src: nrpe/ + dest: /etc/nagios/plugins/ + owner: root + group: root + mode: u=rwx,g=rx,o=rx + notify: restart-nrpe +- name: Add nagios to sudoers + copy: + src: sudoers + dest: /etc/sudoers.d/nagios + mode: u=rw,g=r,o= + owner: root + group: root + notify: restart-nrpe diff --git a/roles/pve/tasks/vhost.yml b/roles/pve/tasks/vhost.yml new file mode 100644 index 0000000..81bc001 --- /dev/null +++ b/roles/pve/tasks/vhost.yml @@ -0,0 +1,8 @@ +- name: Configure memory regions + copy: + src: vhost.conf + dest: /etc/modprobe.d/ + mode: u=rw,g=r,o=r + owner: root + group: root + notify: restart-sysctl diff --git a/roles/secure-grub/handlers/main.yml b/roles/secure-grub/handlers/main.yml new file mode 100644 index 0000000..5b3125c --- /dev/null +++ b/roles/secure-grub/handlers/main.yml @@ -0,0 +1,2 @@ +- name: grub-register + command: update-grub diff --git a/roles/secure-grub/tasks/main.yml b/roles/secure-grub/tasks/main.yml new file mode 100644 index 0000000..dd4acb3 --- /dev/null +++ b/roles/secure-grub/tasks/main.yml @@ -0,0 +1,7 @@ +- name: GRUB boot password protection + blockinfile: + path: /etc/grub.d/40_custom + block: | + set superusers="{{ grub_user }}" + password_pbkdf2 {{ grub_user }} {{ grub_code }} + notify: grub-register diff --git a/roles/secure-grub/vars/main.yaml b/roles/secure-grub/vars/main.yaml new file mode 100644 index 0000000..875fc0c --- /dev/null +++ b/roles/secure-grub/vars/main.yaml @@ -0,0 +1 @@ +grub_user: admin diff --git a/roles/send-mail/tasks/main.yml b/roles/send-mail/tasks/main.yml new file mode 100644 index 0000000..071e12f --- /dev/null +++ b/roles/send-mail/tasks/main.yml @@ -0,0 +1,10 @@ +- name: Send mail using own SMTP server + community.general.mail: + host: "{{ smtp_server }}" + port: 465 + username: "{{ awx_email }}" + password: "{{ awx_smtp_password }}" + to: "{{ sysadmin_mail }}" + subject: Ansible test + body: System {{ ansible_fqdn }} has sent the email successfully. + delegate_to: localhost diff --git a/run-playbook.sh b/run-playbook.sh new file mode 100755 index 0000000..23f5d6a --- /dev/null +++ b/run-playbook.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +EXTRA_ARGS=() + +if [ -f .passbolt.yml ]; then + EXTRA_ARGS+=("--extra-vars" "@.passbolt.yml") +fi +if [ -f .vault-pass ]; then + EXTRA_ARGS+=("--vault-password-file" ".vault-pass") +fi + +#export PYTHONPATH=./venv/lib/python3.12/site-packages/ +ansible-playbook ${EXTRA_ARGS[@]} $@ diff --git a/windows-install-package.yml b/windows-install-package.yml deleted file mode 100644 index c9e0d28..0000000 --- a/windows-install-package.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -- name: Installing Apache MSI - hosts: W2019 - - tasks: - - name: Download the Apache installer - win_get_url: - url: https://archive.apache.org/dist/httpd/binaries/win32/httpd-2.2.25-win32-x86-no_ssl.msi - dest: C:\ansible_examples\httpd-2.2.25-win32-x86-no_ssl.msi - - - name: Install MSI - win_package: - path: C:\ansible_examples\httpd-2.2.25-win32-x86-no_ssl.msi - state: present \ No newline at end of file diff --git a/windows-ping-test.yml b/windows-ping-test.yml deleted file mode 100644 index 544b237..0000000 --- a/windows-ping-test.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -- name: Ping Windows hosts - hosts: W2019 - tasks: - - name: Ping Windows hosts using win_ping module - ansible.windows.win_ping: \ No newline at end of file diff --git a/windows-restart_service.yml b/windows-restart_service.yml deleted file mode 100644 index 4ea40c3..0000000 --- a/windows-restart_service.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- hosts: W2019 - tasks: - - name: Stop service WSearch - win_service: - name: wuauserv - state: stopped \ No newline at end of file diff --git a/windows-update_windows.yaml b/windows-update_windows.yaml deleted file mode 100644 index 3fe6c9b..0000000 --- a/windows-update_windows.yaml +++ /dev/null @@ -1,31 +0,0 @@ -- hosts: windows - ignore_unreachable: yes - serial: 1 - tasks: - # Check if there are missing updates - - block: - - name: Check for missing updates. - win_updates: state=searched - register: update_count - #Install missing updates only if at least one is missing - - block: - - name: Install missing updates. - win_updates: - category_names: '*' - #- Application - #- Connectors - #- DefinitionUpdates - #- DeveloperKits - #- FeaturePacks - #- Guidance - #- ServicePacks - #- Tools - #- UpdateRollups - #- CriticalUpdates - #- SecurityUpdates - log_path: C:\Win_Template_Patch.log - register: update_result - - name: Reboot, if needed. - win_reboot: - when: update_result.reboot_required - when: update_count.found_update_count|int >= 1 \ No newline at end of file