-
Notifications
You must be signed in to change notification settings - Fork 57
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
New time period module #426
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation could be a bit more detailed. Probably, you could use the tasks from your integration test.
I tested the module with some use cases:
- When creating a timeperiod that already exists, a failure is shown (should be "OK").
- When updating a timeperiod without any actual change, the result is "changed" (should be "OK").
- When adding an exclude time range, this isn't visible in the UI.
- When deleting a timeperiod that doesn't exist, a failure is shown (should be "OK").
Here's the playbook i used:
# Make sure to keep the tests in sync!
# Rather use the tests than this playbook directly.
- name: "Test timeperiods"
hosts: all
gather_facts: 'no'
vars_files:
- ./vars/config.yml
tasks:
- name: create timeperiod
checkmk.general.timeperiod:
server_url: "{{ server_url }}"
site: "{{ site }}"
automation_user: "{{ automation_user }}"
automation_secret: "{{ automation_secret }}"
name: "lunch"
alias: "Mahlzeit"
active_time_ranges: [
{
"day": "all",
"time_ranges": [
{
"start": "12:00",
"end": "13:00"
}
]
}
]
state: present
delegate_to: localhost
run_once: 'yes'
# fails. should be "OK"
- name: create timeperiod again
checkmk.general.timeperiod:
server_url: "{{ server_url }}"
site: "{{ site }}"
automation_user: "{{ automation_user }}"
automation_secret: "{{ automation_secret }}"
name: "lunch"
alias: "Mahlzeit"
active_time_ranges: [
{
"day": "all",
"time_ranges": [
{
"start": "12:00",
"end": "13:00"
}
]
}
]
state: present
delegate_to: localhost
run_once: 'yes'
- name: create timeperiod that uses the first one
checkmk.general.timeperiod:
server_url: "{{ server_url }}"
site: "{{ site }}"
automation_user: "{{ automation_user }}"
automation_secret: "{{ automation_secret }}"
name: "working_hours"
alias: "Ballern"
active_time_ranges: [
{
"day": "all",
"time_ranges": [
{
"start": "8:00",
"end": "17:00"
}
]
},
]
exclude: ["Mahlzeit"]
state: present
delegate_to: localhost
run_once: 'yes'
- name: update timeperiod
checkmk.general.timeperiod:
server_url: "{{ server_url }}"
site: "{{ site }}"
automation_user: "{{ automation_user }}"
automation_secret: "{{ automation_secret }}"
name: "working_hours"
active_time_ranges: [
{
"day": "all",
"time_ranges": [
{
"start": "9:00",
"end": "18:00"
}
]
},
]
state: present
delegate_to: localhost
run_once: 'yes'
# fails. should be "OK"
- name: update timeperiod. again.
checkmk.general.timeperiod:
server_url: "{{ server_url }}"
site: "{{ site }}"
automation_user: "{{ automation_user }}"
automation_secret: "{{ automation_secret }}"
name: "working_hours"
active_time_ranges: [
{
"day": "all",
"time_ranges": [
{
"start": "9:00",
"end": "18:00"
}
]
},
]
state: present
delegate_to: localhost
run_once: 'yes'
- name: remove used timeperiod
checkmk.general.timeperiod:
server_url: "{{ server_url }}"
site: "{{ site }}"
automation_user: "{{ automation_user }}"
automation_secret: "{{ automation_secret }}"
name: "lunch"
state: absent
delegate_to: localhost
run_once: 'yes'
ignore_errors: true
- name: remove timeperiod
checkmk.general.timeperiod:
server_url: "{{ server_url }}"
site: "{{ site }}"
automation_user: "{{ automation_user }}"
automation_secret: "{{ automation_secret }}"
name: "working_hours"
state: absent
delegate_to: localhost
run_once: 'yes'
# fails. should be "OK"
- name: remove timeperiod again
checkmk.general.timeperiod:
server_url: "{{ server_url }}"
site: "{{ site }}"
automation_user: "{{ automation_user }}"
automation_secret: "{{ automation_secret }}"
name: "working_hours"
state: absent
delegate_to: localhost
run_once: 'yes'
- name: remove used timeperiod
checkmk.general.timeperiod:
server_url: "{{ server_url }}"
site: "{{ site }}"
automation_user: "{{ automation_user }}"
automation_secret: "{{ automation_secret }}"
name: "lunch"
state: absent
delegate_to: localhost
run_once: 'yes'
Hi Lars, thanks for the feedback. I had a dumb mistake in it, which is now corrected. Please try it again. Nice weekend! ;) |
|
timeperiodupdate = TimeperiodUpdateAPI(module) | ||
timeperiodupdate.headers["If-Match"] = result.etag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An Update should only be done in the case the mentioned parameters are different in the already existing Timeperiod.
Otherwise running the same playbook again and again will always do a change in the environment. You have to avoid this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea, but this will need a lot of time to accomplish.
So as example we want to update a time period for all weekdays with these time ranges:
active_time_ranges: '[{"day": "all", "time_ranges": [{"start": "08:00:00", "end": "17:00:00"}]}]'
And we try to compare this with the existing time ranges of a time period, we get this:
[{'day': 'monday', 'time_ranges': [{'start': '08:00', 'end': '17:00'}]}, {'day': 'tuesday', 'time_ranges': [{'start': '08:00', 'end': '17:00'}]}, {'day': 'wednesday', 'time_ranges': [{'start': '08:00', 'end': '17:00'}]}, {'day': 'thursday', 'time_ranges': [{'start': '08:00', 'end': '17:00'}]}, {'day': 'friday', 'time_ranges': [{'start': '08:00', 'end': '17:00'}]}, {'day': 'saturday', 'time_ranges': [{'start': '08:00', 'end': '17:00'}]}, {'day': 'sunday', 'time_ranges': [{'start': '08:00', 'end': '17:00'}]}]
So we would need to adjust
- the given time ranges to every single day of the week
- remove the seconds from the input, as internally there are no seconds (in contrast to the API Docs example...)
We redirect the raw data to the API so at first you would have to convert the data to something you can work with in python.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, that's too complex.
But what do you think of this as an intermediate solution:
If the data provided by the task is completely equal with the current data from the API, we don't change anything. But if the task e.g. has seconds in the data, and the API has not, we do post a change to the API.
Many users are running their playbooks daily or hourly, and that would help them a lot, already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please have a look at my last commit. Now there is a rudimentary comparison between existing and new values.
Based on that we could add the other checks (full week and seconds) sometime.
Nice weekent y'all! |
You're right. I just had a look at some other modules and as far i see at the moment we're not really consistent for all modules here. ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works as described. :-)
@Max-checkmk please check the failing sanity check and fix it. I think we had this issue with the host or folder module in the past. Maybe @lgetwan can help here. |
Well, the problem seems to be inside the folder-module and not in this module. As far as i can read the logs from the test... |
True. Then we will ignore the failing test here and fix it in |
Pull request type
Please check the type of change your PR introduces:
What is the current behavior?
There is no module for time periods
What is the new behavior?
Other information