Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nagios module to recognize if file exists and is fifo pipe #58569

Merged
merged 1 commit into from
Jul 6, 2019

Conversation

Klaas-
Copy link
Contributor

@Klaas- Klaas- commented Jun 30, 2019

SUMMARY

Ansible nagios module does not check if cmdfile is actually a fifo file. If the file does not exist (for example nagios is not started, it will create a normal file. If the file exists nagios won't start.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

lib/ansible/modules/monitoring/nagios.py

ADDITIONAL INFORMATION

Before change:

[klaas@notebook ~]$ file /home/klaas/test.file
/home/klaas/test.file: cannot open `/home/klaas/test.file' (No such file or directory)
[klaas@notebook ~]$ ansible -i "localhost," --connection local -m nagios -a "action=downtime cmdfile=/home/klaas/test.file command=host comment=test host=test.tld services=host " all
[DEPRECATION WARNING]: Distribution fedora 30 on host localhost should use /usr/bin/python3, but is using /usr/bin/python for backward compatibility 
with prior Ansible releases. A future Ansible release will default to using the discovered platform python for this host. See 
https://docs.ansible.com/ansible/2.8/reference_appendices/interpreter_discovery.html for more information. This feature will be removed in version 
2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
localhost | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": true,
    "nagios_commands": [
        "[1561907405] SCHEDULE_HOST_DOWNTIME;test.tld;1561907405;1561909205;1;0;1800;Ansible;test"
    ]
}
[klaas@notebook ~]$ file /home/klaas/test.file
/home/klaas/test.file: JSON data

After change (file doesn't exist):

[klaas@notebook ~]$ rm test.file 
[klaas@notebook ~]$ ansible -i "localhost," --connection local -m nagios -a "action=downtime cmdfile=/home/klaas/test.file command=host comment=test host=test.tld services=host" all
[DEPRECATION WARNING]: Distribution fedora 30 on host localhost should use /usr/bin/python3, but is using /usr/bin/python for backward compatibility 
with prior Ansible releases. A future Ansible release will default to using the discovered platform python for this host. See 
https://docs.ansible.com/ansible/2.8/reference_appendices/interpreter_discovery.html for more information. This feature will be removed in version 
2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
localhost | FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "cmdfile": "/home/klaas/test.file",
    "msg": "nagios command file does not exist"
}

After change file not fifo:

[klaas@notebook ~]$ touch test.file
[klaas@notebook ~]$ ansible -i "localhost," --connection local -m nagios -a "action=downtime cmdfile=/home/klaas/test.file command=host comment=test host=test.tld services=host" all
[DEPRECATION WARNING]: Distribution fedora 30 on host localhost should use /usr/bin/python3, but is using /usr/bin/python for backward compatibility 
with prior Ansible releases. A future Ansible release will default to using the discovered platform python for this host. See 
https://docs.ansible.com/ansible/2.8/reference_appendices/interpreter_discovery.html for more information. This feature will be removed in version 
2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
localhost | FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "cmdfile": "/home/klaas/test.file",
    "msg": "nagios command file is not a fifo file"
}

After change file is fifo: (you'll need to cat test.file from another shell)

[klaas@notebook ~]$ mkfifo test.file
[klaas@notebook ~]$ ansible -i "localhost," --connection local -m nagios -a "action=downtime cmdfile=/home/klaas/test.file command=host comment=test host=test.tld services=host" all
[DEPRECATION WARNING]: Distribution fedora 30 on host localhost should use /usr/bin/python3, but is using /usr/bin/python for backward compatibility 
with prior Ansible releases. A future Ansible release will default to using the discovered platform python for this host. See 
https://docs.ansible.com/ansible/2.8/reference_appendices/interpreter_discovery.html for more information. This feature will be removed in version 
2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
localhost | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": true,
    "nagios_commands": [
        "[1561909146] SCHEDULE_HOST_DOWNTIME;test.tld;1561909146;1561910946;1;0;1800;Ansible;test"
    ]
}

@ansibot
Copy link
Contributor

ansibot commented Jun 30, 2019

@ansibot ansibot added affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. monitoring Monitoring category needs_triage Needs a first human triage before being processed. python3 support:community This issue/PR relates to code supported by the Ansible community. labels Jun 30, 2019
Copy link
Contributor

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks ok. You need a changelog fragment, though.

@Klaas- Klaas- force-pushed the Klaas-nagios_fifofile branch 2 times, most recently from 7bcbb37 to 4e7a43a Compare June 30, 2019 20:55
@Klaas-
Copy link
Contributor Author

Klaas- commented Jun 30, 2019

@felixfontein thanks for looking over this -- added the changelog fragement

@ansibot
Copy link
Contributor

ansibot commented Jul 1, 2019

@Klaas- This PR contains @ mentions in at least one commit message. Those mentions can cause cascading notifications through GitHub and need to be removed. Please squash or amend your commits to remove the mentions.

click here for bot help

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Jul 1, 2019
add felixfontein suggestion to changelogs/fragments/58569-nagios-fifo-fix.yaml

Co-Authored-By: Felix Fontein <felix@fontein.de>
@Klaas-
Copy link
Contributor Author

Klaas- commented Jul 1, 2019

fixed the issue with the @ in commit message and squashed the two commits

@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Jul 1, 2019
Copy link
Contributor

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@felixfontein felixfontein merged commit faf50db into ansible:devel Jul 6, 2019
@felixfontein
Copy link
Contributor

@Klaas- thank you very much for fixing this! I'll create a backport PR so this will hopefully be included in the next 2.8.x release.

felixfontein pushed a commit to felixfontein/ansible that referenced this pull request Jul 6, 2019
…le#58569)

add felixfontein suggestion to changelogs/fragments/58569-nagios-fifo-fix.yaml

Co-Authored-By: Felix Fontein <felix@fontein.de>
(cherry picked from commit faf50db)
@sivel sivel removed the needs_triage Needs a first human triage before being processed. label Jul 8, 2019
abadger pushed a commit that referenced this pull request Jul 16, 2019
add felixfontein suggestion to changelogs/fragments/58569-nagios-fifo-fix.yaml

Co-Authored-By: Felix Fontein <felix@fontein.de>
(cherry picked from commit faf50db)
@ansible ansible locked and limited conversation to collaborators Aug 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. monitoring Monitoring category python3 support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants