Skip to content

Commit

Permalink
feat: add support for uptime kuma 1.20.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasheld committed Feb 13, 2023
1 parent c0ed576 commit d87a9ca
Show file tree
Hide file tree
Showing 29 changed files with 296 additions and 36 deletions.
2 changes: 1 addition & 1 deletion plugins/doc_fragments/uptime_kuma.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

# Copyright: (c) 2022, Lucas Held <[email protected]>
# Copyright: (c) 2023, Lucas Held <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright: (c) 2022, Lucas Held <[email protected]>
# Copyright: (c) 2023, Lucas Held <[email protected]>

from __future__ import absolute_import, division, print_function

Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/docker_host.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright: (c) 2022, Lucas Held <[email protected]>
# Copyright: (c) 2023, Lucas Held <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/docker_host_info.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright: (c) 2022, Lucas Held <[email protected]>
# Copyright: (c) 2023, Lucas Held <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
Expand Down
116 changes: 116 additions & 0 deletions plugins/modules/game_list_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright: (c) 2023, Lucas Held <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function

__metaclass__ = type


DOCUMENTATION = r'''
---
extends_documentation_fragment:
- lucasheld.uptime_kuma.uptime_kuma
module: game_list_info
author: Lucas Held (@lucasheld)
short_description: Retrieves facts about the games that are supported by the GameDig monitor type.
description: Retrieves facts about the games that are supported by the GameDig monitor type.
'''

EXAMPLES = r'''
- name: get game list
lucasheld.uptime_kuma.game_list_info:
api_url: http://127.0.0.1:3001
api_username: admin
api_password: secret123
register: result
'''

RETURN = r'''
game_list:
description: The game list
returned: always
type: complex
contains:
extra:
description: The extra value of the game.
returned: always
type: dict
sample: {}
keys:
description: The keys of the game.
returned: always
type: list
elements: str
sample: ["7d2d"]
options:
description: The options of the game.
returned: always
type: dict
sample: {"port": 26900, "port_query_offset": 1, "protocol": "valve"}
pretty:
description: The title of the game.
returned: always
type: str
sample: "7 Days to Die (2013)"
'''

import traceback

from ansible.module_utils.basic import AnsibleModule
from ansible_collections.lucasheld.uptime_kuma.plugins.module_utils.common import common_module_args
from ansible.module_utils.basic import missing_required_lib

try:
from uptime_kuma_api import UptimeKumaApi
HAS_UPTIME_KUMA_API = True
except ImportError:
HAS_UPTIME_KUMA_API = False


def run(api, params, result):
result["game_list"] = api.get_game_list()


def main():
module_args = dict()
module_args.update(common_module_args)

module = AnsibleModule(module_args, supports_check_mode=True)
params = module.params

if not HAS_UPTIME_KUMA_API:
module.fail_json(msg=missing_required_lib("uptime_kuma_api"))

api = UptimeKumaApi(params["api_url"])
api_token = params.get("api_token")
api_username = params.get("api_username")
api_password = params.get("api_password")
if api_token:
api.login_by_token(api_token)
elif api_username and api_password:
api.login(api_username, api_password)
else:
# autoLogin for enabled disableAuth
api.login()

result = {
"changed": False
}

try:
run(api, params, result)

api.disconnect()
module.exit_json(**result)
except Exception:
api.disconnect()
error = traceback.format_exc()
module.fail_json(msg=error, **result)


if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion plugins/modules/login.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright: (c) 2022, Lucas Held <[email protected]>
# Copyright: (c) 2023, Lucas Held <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/maintenance.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright: (c) 2022, Lucas Held <[email protected]>
# Copyright: (c) 2023, Lucas Held <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/maintenance_info.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright: (c) 2022, Lucas Held <[email protected]>
# Copyright: (c) 2023, Lucas Held <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
Expand Down
26 changes: 22 additions & 4 deletions plugins/modules/monitor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright: (c) 2022, Lucas Held <[email protected]>
# Copyright: (c) 2023, Lucas Held <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
Expand Down Expand Up @@ -33,7 +33,7 @@
type:
description: The type of the monitor.
type: str
choices: ["http", "port", "ping", "keyword", "grpc-keyword", "dns", "docker", "push", "steam", "mqtt", "sqlserver", "postgres", "mysql", "radius"]
choices: ["http", "port", "ping", "keyword", "grpc-keyword", "dns", "docker", "push", "steam", "gamedig", "mqtt", "sqlserver", "postgres", "mysql", "mongodb", "radius", "redis"]
interval:
description: The heartbeat interval of the monitor.
type: int
Expand Down Expand Up @@ -148,6 +148,9 @@
hostname:
description: The hostname of the monitor.
type: str
packetSize:
description: The packet size of the monitor.
type: int
port:
description: The port of the monitor.
type: int
Expand Down Expand Up @@ -203,6 +206,9 @@
radiusCallingStationId:
description: The radius calling station id of the monitor.
type: str
game:
description: The game of the monitor.
type: str
state:
description:
- Set to C(present) to create/update a monitor.
Expand Down Expand Up @@ -289,6 +295,10 @@ def run(api, params, result):
params["databaseConnectionString"] = "postgres://username:password@host:port/database"
elif params["type"] == MonitorType.MYSQL:
params["databaseConnectionString"] = "mysql://username:password@host:port/database"
elif params["type"] == MonitorType.MONGODB:
params["databaseConnectionString"] = "mongodb://username:password@host:port/database"
elif params["type"] == MonitorType.REDIS:
params["databaseConnectionString"] = "redis://user:password@host:port"

if not params["port"]:
if type == MonitorType.DNS:
Expand Down Expand Up @@ -353,7 +363,7 @@ def main():
module_args = dict(
id=dict(type="int"),
name=dict(type="str"),
type=dict(type="str", choices=["http", "port", "ping", "keyword", "dns", "docker", "push", "steam", "mqtt", "sqlserver", "postgres", "mysql", "radius"]),
type=dict(type="str", choices=["http", "port", "ping", "keyword", "grpc-keyword", "dns", "docker", "push", "steam", "gamedig", "mqtt", "sqlserver", "postgres", "mysql", "mongodb", "radius", "redis"]),
interval=dict(type="int"),
retryInterval=dict(type="int"),
resendInterval=dict(type="int"),
Expand Down Expand Up @@ -397,6 +407,9 @@ def main():
# PORT, PING, DNS, STEAM, MQTT
hostname=dict(type="str"),

# PING
packetSize=dict(type="int"),

# PORT, DNS, STEAM, MQTT, RADIUS
port=dict(type="int"),

Expand All @@ -410,8 +423,10 @@ def main():
mqttTopic=dict(type="str"),
mqttSuccessMessage=dict(type="str"),

# SQLSERVER, POSTGRES, MYSQL
# SQLSERVER, POSTGRES, MYSQL, MONGODB, REDIS
databaseConnectionString=dict(type="str"),

# SQLSERVER, POSTGRES, MYSQL
databaseQuery=dict(type="str"),

# DOCKER
Expand All @@ -426,6 +441,9 @@ def main():
radiusCalledStationId=dict(type="str"),
radiusCallingStationId=dict(type="str"),

# GAMEDIG
game=dict(type="str"),

state=dict(type="str", default="present", choices=["present", "absent", "paused", "resumed"])
)
module_args.update(common_module_args)
Expand Down
57 changes: 56 additions & 1 deletion plugins/modules/monitor_info.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright: (c) 2022, Lucas Held <[email protected]>
# Copyright: (c) 2023, Lucas Held <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
Expand Down Expand Up @@ -277,6 +277,61 @@
returned: always
type: str
sample: None
radiusCalledStationId:
description: The radiusCalledStationId of the monitor.
returned: always
type: str
sample: None
radiusCallingStationId:
description: The radiusCallingStationId of the monitor.
returned: always
type: str
sample: None
radiusUsername:
description: The radiusUsername of the monitor.
returned: always
type: str
sample: None
radiusPassword:
description: The radiusPassword of the monitor.
returned: always
type: str
sample: None
radiusSecret:
description: The radiusSecret of the monitor.
returned: always
type: str
sample: None
resendInterval:
description: The resendInterval of the monitor.
returned: always
type: int
sample: 0
packetSize:
description: The packetSize of the monitor.
returned: always
type: int
sample: 56
includeSensitiveData:
description: The includeSensitiveData of the monitor.
returned: always
type: bool
sample: True
game:
description: The game of the monitor.
returned: always
type: str
sample: '7d2d'
docker_host:
description: The docker_host of the monitor.
returned: always
type: int
sample: None
docker_container:
description: The docker_container of the monitor.
returned: always
type: str
sample: ""
'''

import traceback
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/monitor_tag.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright: (c) 2022, Lucas Held <[email protected]>
# Copyright: (c) 2023, Lucas Held <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/notification.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright: (c) 2022, Lucas Held <[email protected]>
# Copyright: (c) 2023, Lucas Held <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/notification_info.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright: (c) 2022, Lucas Held <[email protected]>
# Copyright: (c) 2023, Lucas Held <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/proxy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright: (c) 2022, Lucas Held <[email protected]>
# Copyright: (c) 2023, Lucas Held <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/proxy_info.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright: (c) 2022, Lucas Held <[email protected]>
# Copyright: (c) 2023, Lucas Held <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright: (c) 2022, Lucas Held <[email protected]>
# Copyright: (c) 2023, Lucas Held <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/settings_info.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright: (c) 2022, Lucas Held <[email protected]>
# Copyright: (c) 2023, Lucas Held <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
Expand Down
Loading

0 comments on commit d87a9ca

Please sign in to comment.