diff --git a/CHANGELOG.md b/CHANGELOG.md index 27288389..ef47af93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ The **patch** part changes is incremented if multiple releases happen the same m ### Added * userlogrotate: rotate also php.log. +* nagios-nrpe: add a NRPE check-local command with completion. ### Changed * evolinux-users: remove Stretch references in tasks that also apply to next Debian versions. diff --git a/nagios-nrpe/files/check-local b/nagios-nrpe/files/check-local new file mode 100755 index 00000000..4d96c639 --- /dev/null +++ b/nagios-nrpe/files/check-local @@ -0,0 +1,12 @@ +#!/usr/bin/bash + +if ! test -f /usr/lib/nagios/plugins/check_nrpe; then + echo '/usr/lib/nagios/plugins/check_nrpe is missing, please install nagios-nrpe-plugin package.' + exit 1 +fi + + + +/usr/lib/nagios/plugins/check_nrpe -H 127.0.0.1 -c check_$1 + + diff --git a/nagios-nrpe/files/check-local_completion b/nagios-nrpe/files/check-local_completion new file mode 100644 index 00000000..040d60d4 --- /dev/null +++ b/nagios-nrpe/files/check-local_completion @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +_check_local_dynamic_completion() { + local cur; + cur=${COMP_WORDS[COMP_CWORD]}; + check_list=$(grep 'check_' /etc/nagios/nrpe.d/evolix.cfg | grep -vE '^[[:blank:]]*#' | awk -F'[\[\]=_]' '{print $3}') + COMPREPLY=(); + COMPREPLY=( $( compgen -W '$(grep check_ /etc/nagios/nrpe.d/evolix.cfg | grep -vE "^[[:blank:]]*#" | awk -F"[\[\]=_]" "{print \$3}")' -- $cur ) ); +} + +complete -F _check_local_dynamic_completion check-local + + diff --git a/nagios-nrpe/tasks/check-local.yml b/nagios-nrpe/tasks/check-local.yml new file mode 100644 index 00000000..6718da3f --- /dev/null +++ b/nagios-nrpe/tasks/check-local.yml @@ -0,0 +1,24 @@ +--- +# Install check-local utilitary +# This task is for Debian >= 10 only! + +- name: Package nagios-nrpe-plugin is intalled + ansible.builtin.apt: + name: nagios-nrpe-plugin + when: ansible_distribution_major_version is version('10', '>=') + +- name: Utilitary check-local is installed + ansible.builtin.copy: + src: check-local + dest: /usr/local/bin/check-local + mode: "0755" + when: ansible_distribution_major_version is version('10', '>=') + +- name: Completion for utilitary check-local is installed + ansible.builtin.copy: + src: check-local_completion + dest: /etc/bash_completion.d/check-local + mode: "0755" + when: ansible_distribution_major_version is version('10', '>=') + + diff --git a/nagios-nrpe/tasks/main.yml b/nagios-nrpe/tasks/main.yml index c05cf85a..607335e1 100644 --- a/nagios-nrpe/tasks/main.yml +++ b/nagios-nrpe/tasks/main.yml @@ -84,4 +84,7 @@ tags: - nagios-nrpe -- ansible.builtin.include_tasks: wrapper.yml \ No newline at end of file +- ansible.builtin.include_tasks: wrapper.yml + +- ansible.builtin.include_tasks: check-local.yml + when: ansible_distribution_major_version is version('10', '>=')