Split wrapper.yml, déplacement sbin -> bin, min mini-fixes
All checks were successful
Ansible Lint |Total|New|Outstanding|Fixed|Trend |:-:|:-:|:-:|:-:|:-: |2700|0|2700|0|:zzz:
gitea/ansible-roles/pipeline/head This commit looks good

This commit is contained in:
William Hirigoyen 2024-04-03 12:01:03 +02:00
parent ed02e2dfa7
commit dc74978542
6 changed files with 64 additions and 30 deletions

View file

@ -44,23 +44,23 @@ function enable_wrapper() {
function main() {
is_disabled="$(is_disabled "${wrapper_name}")"
if [ -e "${disable_file}" ] && [ "${is_disabled}" == "False" ]; then
if [ -e "${disable_file}" ] && [ "${is_disabled}" = "False" ]; then
enable_wrapper "${wrapper_name}"
fi
timeout_command=""
if [ "${is_disabled}" == "True" ]; then
if [ "${is_disabled}" = "True" ]; then
timeout_command="timeout 9"
fi
check_stdout="$(${timeout_command} ${check_command})"
check_rc=$?
if [ "${is_disabled}" == "True" ] && [ "${check_rc}" -eq 124 ] && [ -z "${check_stdout}" ]; then
if [ "${is_disabled}" = "True" ] && [ "${check_rc}" -eq 124 ] && [ -z "${check_stdout}" ]; then
check_stdout="Check timeout (9 sec)"
fi
if [ "${is_disabled}" == "True" ]; then
if [ "${is_disabled}" = "True" ]; then
enable_time="$(get_enable_time "${wrapper_name}")"
enable_delay="$(enable_delay "${enable_time}")"
delay_str="$(delay_to_string "${enable_delay}")"
@ -74,7 +74,7 @@ function main() {
echo "${check_stdout}"
fi
if [ "${is_disabled}" == "True" ]; then
if [ "${is_disabled}" = "True" ]; then
if [ ${check_rc} = 0 ]; then
exit 0 # Nagios OK
else

View file

@ -122,14 +122,13 @@ function check() {
else
check_commands="$(get_check_commands "${check}")"
if [ -n "${check_commands}" ]; then
check_command="$(echo "${check_commands}")"
check_command="$(echo "${check_commands}" | tail -n1)"
request_command="sudo -u nagios -- ${check_command}"
else
if [ -z "${1}" ] || [ "${1}" = "all" ]; then
err_msg="Check command not found in NRPE configuration."
else
err_mgs="Error: no command found in NRPE configuration for check '${check}'. Aborted."
err_msg="Error: no command found in NRPE configuration for check '${check}'. Aborted."
fi
fi
fi
@ -138,8 +137,6 @@ function check() {
rc="$?"
check_output="$(echo "${check_output}" | tr '\n' ' ')"
if [ -z "${1}" ] || [ "${1}" = "all" ]; then
term_cols="$(tput cols)"
if [ "${#check_output}" -gt 60 ]; then
check_output="$(echo "${check_output}" | cut -c-80) [...]"
fi

View file

@ -204,7 +204,7 @@ function _get_conf_from_dir() {
fi
# Add conf files in dir to be processed recursively
for _file in $(find "${1}" -maxdepth 1 -name "*.cfg" | ${_sort_command}); do
for _file in $(find "${1}" -maxdepth 1 -name "*.cfg" >2 /dev/null | ${_sort_command}); do
if [ -f "${_file}" ]; then
_get_conf_from_file "${_file}"
elif [ -d "${_file}" ]; then

View file

@ -93,4 +93,5 @@
- ansible.builtin.include_tasks: wrapper.yml
- ansible.builtin.include_tasks: check-local.yml
- ansible.builtin.include_tasks: monitoringctl.yml

View file

@ -0,0 +1,44 @@
---
- name: "Remount /usr if needed"
ansible.builtin.include_role:
name: remount-usr
- name: "dir /usr/local/lib/monitoringctl/ exists"
ansible.builtin.file:
path: /usr/local/lib/monitoringctl/
state: directory
mode: '0755'
- name: "monitoringctl is not in /usr/local/sbin/"
ansible.builtin.file:
path: /usr/local/sbin/monitoringctl
state: absent
- name: "copy monitoringctl"
ansible.builtin.copy:
src: monitoringctl
dest: /usr/local/bin/monitoringctl
owner: root
group: root
mode: "0750"
force: true
- name: "copy monitoringctl_common lib"
ansible.builtin.copy:
src: monitoringctl_common
dest: /usr/local/lib/monitoringctl/common
owner: root
group: root
mode: "0644"
force: true
- name: "copy monitoringctl_completion script"
ansible.builtin.copy:
src: monitoringctl_completion
dest: /etc/bash_completion.d/monitoringctl
owner: root
group: root
mode: "0644"
force: true

View file

@ -38,6 +38,16 @@
state: link
when: old_alerts_switch.stat.exists
- name: "Nagios user can run alerts_switch with sudo (used by alerts_wrapper)"
ansible.builtin.lineinfile:
path: /etc/sudoers.d/evolinux
regexp: "nagios.*alerts_switch"
line: "nagios ALL = NOPASSWD:/usr/local/bin/alerts_switch *"
owner: root
group: root
mode: "640"
validate: "visudo -c -f /etc/sudoers.d/evolinux"
- name: "check if old alerts_wrapper script is present"
ansible.builtin.stat:
path: "{{ nagios_plugins_directory }}/alerts_wrapper"
@ -65,15 +75,6 @@
state: link
when: old_alerts_wrapper.stat.exists
- name: "copy monitoringctl"
ansible.builtin.copy:
src: monitoringctl
dest: /usr/local/sbin/monitoringctl
owner: root
group: root
mode: "0755"
force: true
- name: "copy monitoringctl_common lib"
ansible.builtin.copy:
src: monitoringctl_common
@ -83,12 +84,3 @@
mode: "0644"
force: true
- name: "copy monitoringctl_completion script"
ansible.builtin.copy:
src: monitoringctl_completion
dest: /etc/bash_completion.d/monitoringctl
owner: root
group: root
mode: "0644"
force: true