-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from bodsch/feature/support-loki-3
supports loki v3
- Loading branch information
Showing
61 changed files
with
1,104 additions
and
296 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,6 +170,8 @@ jobs: | |
- with-updates | ||
- "2.5" | ||
- "2.6" | ||
- "2.7" | ||
- "3.2" | ||
collection_role: | ||
- loki | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,7 +99,6 @@ def keyfiles(self, data): | |
|
||
return result | ||
|
||
|
||
def content_security_policy(self, data): | ||
""" | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
#!/usr/bin/python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
# (c) 2022, Bodo Schulz <[email protected]> | ||
|
||
from __future__ import absolute_import, division, print_function | ||
from ansible.module_utils.basic import AnsibleModule | ||
|
||
# import os | ||
# from requests.exceptions import ConnectionError | ||
import json | ||
# import requests | ||
# from pathlib import Path | ||
|
||
# --------------------------------------------------------------------------------------- | ||
|
||
DOCUMENTATION = """ | ||
module: loki_verify_config | ||
version_added: 1.1.0 | ||
author: "Bodo Schulz (@bodsch) <[email protected]>" | ||
short_description: TBD | ||
description: | ||
- TBD | ||
""" | ||
|
||
EXAMPLES = """ | ||
""" | ||
|
||
RETURN = """ | ||
""" | ||
|
||
# --------------------------------------------------------------------------------------- | ||
|
||
|
||
class LokiVerifyConfig(object): | ||
|
||
def __init__(self, module): | ||
""" | ||
""" | ||
self.module = module | ||
|
||
self.log_level = module.params.get("log_level") | ||
self.config_file = module.params.get("config_file") | ||
|
||
self._loki_cli = module.get_bin_path("loki", True) | ||
|
||
def run(self): | ||
""" | ||
/usr/bin/loki -verify-config -log.format json -log.level debug -config.file /etc/loki/loki.yml | ||
""" | ||
result = dict( | ||
rc=0, | ||
failed=False, | ||
changed=False, | ||
msg="Loki verify config ..." | ||
) | ||
|
||
_failed = True | ||
|
||
args = [] | ||
|
||
args.append(self._loki_cli) | ||
args.append("-verify-config") | ||
|
||
args.append("-log.format") | ||
args.append("json") | ||
|
||
if self.log_level: | ||
args.append("-log.level") | ||
args.append(self.log_level) | ||
|
||
if self.config_file: | ||
args.append("-config.file") | ||
args.append(self.config_file) | ||
|
||
rc, out, err = self.__exec(args, check_rc=False) | ||
|
||
err = err.strip() | ||
# self.module.log(msg=f" -> '{err}' ({type(err)})") | ||
|
||
if rc == 0: | ||
_failed = False | ||
|
||
if rc != 0 and len(err) > 0: | ||
if isinstance(err, str): | ||
err = json.loads(err) | ||
|
||
if isinstance(err, dict): | ||
# log_level = err.get("level", "info") | ||
error_msg = err.get("err", None) | ||
msg = err.get("msg", None) | ||
# if log_level == "warn": | ||
# msg = error_msg = err.get("msg", None) | ||
if rc != 0 and error_msg: | ||
msg = error_msg.split("\n") | ||
else: | ||
msg = err | ||
else: | ||
msg = "unknow config error." | ||
|
||
result = dict( | ||
failed=_failed, | ||
changed=False, | ||
cmd=" ".join(args), | ||
msg=msg | ||
) | ||
|
||
return result | ||
|
||
def __exec(self, commands, check_rc=True): | ||
""" | ||
""" | ||
rc, out, err = self.module.run_command(commands, check_rc=check_rc) | ||
# self.module.log(msg=f" rc : '{rc}'") | ||
# self.module.log(msg=f" out: '{out}'") | ||
# self.module.log(msg=f" err: '{err}'") | ||
return rc, out, err | ||
|
||
|
||
def main(): | ||
""" | ||
""" | ||
specs = dict( | ||
log_level=dict( | ||
default="info", | ||
choices=["debug", "info", "warn", "error"] | ||
), | ||
config_file=dict( | ||
default="/etc/loki/loki.yml", | ||
type="str", | ||
), | ||
) | ||
|
||
module = AnsibleModule( | ||
argument_spec=specs, | ||
supports_check_mode=False, | ||
) | ||
|
||
o = LokiVerifyConfig(module) | ||
result = o.run() | ||
|
||
module.log(msg=f"= result: {result}") | ||
|
||
module.exit_json(**result) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
--- | ||
|
||
grafana_version: 9.4.7 | ||
grafana_version: 11.3.0 | ||
|
||
grafana_scm: | ||
use_tags: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.