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

Add minimal support for diff to monitor plugin #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Javex
Copy link
Contributor

@Javex Javex commented Aug 26, 2023

This change adds very minimal diff support for just the monitor plugin. It only does a diff based on the arguments passed in by the user and only supports only the "present" state.

To support a "full" diff, it would be necessary to make an additional network call to get the new monitor configuration from the instance. To avoid this, the code just diffs the changes passed in.

Please let me know if there's any changes you'd like me to make. I tested this on a local copy using the following playbook:

- hosts: 127.0.0.1
  tasks:
    - name: Setup
      lucasheld.uptime_kuma.setup:
        api_url: http://127.0.0.1:3001
        api_username: admin
        api_password: secret123
    - name: Login to get a token for other roles that want to create monitors
      lucasheld.uptime_kuma.login:
        api_url: http://127.0.0.1:3001
        api_username: admin
        api_password: secret123
      register: uptime_kuma_result
    - name: Set login token
      set_fact:
        uptime_kuma_token: "{{ uptime_kuma_result.token }}" 
    - name: add monitor
      lucasheld.uptime_kuma.monitor:
        api_url: http://127.0.0.1:3001
        api_token: "{{ uptime_kuma_token }}"
        name: google
        type: http
        url: https://google.com
        state: present
    - name: update monitor
      lucasheld.uptime_kuma.monitor:
        api_url: http://127.0.0.1:3001
        api_token: "{{ uptime_kuma_token }}"
        name: google
        type: ping
        hostname: 127.0.0.10
        url: https://google.com
        state: present
    - name: remove monitor
      lucasheld.uptime_kuma.monitor:
        api_url: http://127.0.0.1:3001
        api_token: "{{ uptime_kuma_token }}"
        name: google
        type: http
        url: https://google.com
        state: absent

Putting this file at the repo root and running the following command should execute the playbook: COLLECTIONS_PATHS="./:/usr/share/ansible/collections" ansible-playbook kuma-test-playbook.yml --diff (you may have to adjust the COLLECTIONS_PATH setting to suit your environment.

This should produce the following output (truncated to relevant parts):

TASK [add monitor]
--- before
+++ after
@@ -0,0 +1,5 @@
+accepted_statuscodes:
+- 200-299
+name: google
+type: http
+url: https://google.com

changed: [127.0.0.1]

TASK [update monitor]
--- before
+++ after
@@ -1,6 +1,6 @@
 accepted_statuscodes:
 - 200-299
-hostname: null
+hostname: 127.0.0.10
 name: google
-type: http
+type: ping
 url: https://google.com

changed: [127.0.0.1]

TASK [remove monitor]
changed: [127.0.0.1]

This change adds very minimal diff support for just the monitor plugin.
It only does a diff based on the arguments passed in by the user and
only supports only the "present" state.

To support a "full" diff, it would be necessary to make an additional
network call to get the new monitor configuration from the instance. To
avoid this, the code just diffs the changes passed in.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant