Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

KeyError: 'labels' when using sensu_go_check #124

Closed
adammcdonagh opened this issue Jun 7, 2019 · 5 comments · Fixed by #131
Closed

KeyError: 'labels' when using sensu_go_check #124

adammcdonagh opened this issue Jun 7, 2019 · 5 comments · Fixed by #131
Assignees
Labels
bug Something isn't working

Comments

@adammcdonagh
Copy link

Hi, got a strange one... I don't know enough about Python to understand why this might be happening...

When running the playbook against my own CentOS 7 VM, it works just fine (running Python 2.7.5). However, when I run on our RHEL 7 servers, I get the following error:

Traceback (most recent call last):
  File "/tmp/ansible_E5dwNU/ansible_module_sensu_go_check.py", line 428, in <module>
    main()
  File "/tmp/ansible_E5dwNU/ansible_module_sensu_go_check.py", line 424, in main
    run_module()
  File "/tmp/ansible_E5dwNU/ansible_module_sensu_go_check.py", line 361, in run_module
    check_def = module.create_check_definition()
  File "/tmp/ansible_E5dwNU/ansible_modlib.zip/ansible/module_utils/sensu_go.py", line 187, in create_check_definition
KeyError: 'labels'

I noticed that the way it's checking for labels in metadata if different to the way it's done in the main check script..

I changed:
if self.params['metadata']['labels']:
in sensu_go.py to:
if 'labels' in self.params['metadata'] and self.params['metadata']['labels'] is not None:

and it started working straight away.

Again, I don't understand why it wouldn't work on a RHEL server when it's fine on CentOS with the same version of Python...

Also, I noticed I was getting idempotency failure when creating checks... I had to set a default for interval, since when using cron expressions, the module thinks there's a change..

interval=dict(type='int', default=0)

@jaredledvina jaredledvina self-assigned this Jun 8, 2019
@jaredledvina jaredledvina added the bug Something isn't working label Jun 8, 2019
@jaredledvina
Copy link
Owner

Hey @adammcdonagh

Thanks so much for the bug report! Sounds like I've messed up two things here. I know I didn't fully test the cron setup (mostly since I haven't used them yet on my cluster).

I'm terribly busy over the next week but, I'll try to put some time against this. If you're able to find a fix and want to PR it, feel free to go for it.

@jaredledvina
Copy link
Owner

Hm, I'm not seeing the if self.params['metadata']['labels']: logic in the current version in master (purposely not released yet, trying to get the tests working first):https://github.com/jaredledvina/sensu-go-ansible/blob/master/library/sensu_go_check.py

Would it be possible for you to try again w/ the latest version in master and see if this still happens?

@jaredledvina jaredledvina added the waiting-on-response Waiting for clarification from someone label Jun 8, 2019
@adammcdonagh
Copy link
Author

Hi, I was using the latest version in the master branch. It's the sensu_go.py script that I had to change for the KeyError issue, not the check module itself. Line 185 of https://github.com/jaredledvina/sensu-go-ansible/blob/master/module_utils/sensu_go.py

I think my line numbers are slightly out because I was putting in print statements to try and debug it...

@jaredledvina jaredledvina removed the waiting-on-response Waiting for clarification from someone label Jun 8, 2019
@jaredledvina
Copy link
Owner

Hey @adammcdonagh!

So, #129 should resolve your second issue and includes a simple test to ensure it doesn't break in the future.

Now, for the first one, I'd love to come up with a repro of the problem so that I can ensure there's no regressions going forward. Are you able to share the Ansible task config you used to cause that failure?

I noticed that my integration tests use Python 2.7.16, so it's possible that there was a small change between Python 2.7.5 and Python 2.7.16 that is causing your KeyError. Will I don't think it's doable to test every permutation of Ansible versions + Python versions, I can manually see if I can get 2.7.5 to fail as well.

@jaredledvina
Copy link
Owner

Merged in #131 which should address the first issue as well. Feel free to let me know if you're still hitting problems and we can take another look.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants