lucasheld / ansible-uptime-kuma

Ansible collection of modules to configure Uptime Kuma
GNU General Public License v3.0
135 stars 19 forks source link

monitor_tag TypeError NoneType object is not subscriptable #7

Closed yurinek closed 1 year ago

yurinek commented 1 year ago

Hi,

we try to create a monitor tag

- name: Create first http monitor tag
  lucasheld.uptime_kuma.monitor_tag:
    api_url: "http://{{ kuma_host }}"
    api_token: "{{ api_token }}"
    monitor_name: "api Service"
    tag_name: "tag1"
    value: "namespace: foo"
    state: present

however it outputs

TASK [kuma : Create first http monitor tag] ********************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Traceback (most recent call last):\n  File \"/tmp/ansible_lucasheld.uptime_kuma.monitor_tag_payload_x4o8bo5_/ansible_lucasheld.uptime_kuma.monitor_tag_payload.zip/ansible_collections/lucasheld/uptime_kuma/plugins/modules/monitor_tag.py\", line 155, in main\n  File \"/tmp/ansible_lucasheld.uptime_kuma.monitor_tag_payload_x4o8bo5_/ansible_lucasheld.uptime_kuma.monitor_tag_payload.zip/ansible_collections/lucasheld/uptime_kuma/plugins/modules/monitor_tag.py\", line 111, in run\nTypeError: 'NoneType' object is not subscriptable\n"}

cheers

lucasheld commented 1 year ago

This error means that the tag with the name "tag1" does not exist. The error handling can definitely be improved.

This works for me:

- name: Add monitor
  lucasheld.uptime_kuma.monitor:
    api_url: http://127.0.0.1:3001
    api_username: admin
    api_password: secret123
    name: "api Service"
    type: http
    url: http://127.0.0.1

- name: Add tag
  lucasheld.uptime_kuma.tag:
    api_url: http://127.0.0.1:3001
    api_username: admin
    api_password: secret123
    name: tag1
    color: "#ffffff"

- name: Add monitor tag
  lucasheld.uptime_kuma.monitor_tag:
    api_url: http://127.0.0.1:3001
    api_username: admin
    api_password: secret123
    monitor_name: "api Service"
    tag_name: "tag1"
    value: "namespace: foo"
    state: present
yurinek commented 1 year ago

the difference between tag and monitor_tag was not clear to me. maybe worth to mention it in the docu. thanks for clarification