-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add object and feature for CompatLogger
- Loading branch information
Showing
7 changed files
with
179 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
minor_changes: | ||
- Add object :code:`CompatLogger` and feature :code:`compatlog`. |
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,22 @@ | ||
## CompatLog | ||
|
||
To enable the feature compatlog use the following block in the variable `icinga2_features`. | ||
|
||
**INFO** For detailed information and instructions see the Icinga 2 Docs. [Feature CompatLog](https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#compatlogger) | ||
|
||
``` | ||
icinga2_features: | ||
- name: compatlog | ||
state: present | ||
log_dir: "LogDir + /compat" | ||
rotation_method: "monthly" | ||
``` | ||
|
||
### Feature variables | ||
|
||
* `state: string` | ||
* Enable or disable feature. Options: present, absent | ||
* `log_dir: string` | ||
* Set the log directory. | ||
* `rotation_method: string` | ||
* Set the log rotation interval. Options: hourly, daily, weekly, monthly |
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,128 @@ | ||
from ansible.module_utils.basic import AnsibleModule | ||
|
||
DOCUMENTATION = ''' | ||
name: icinga2_compatlogger | ||
short_description: Creates information for CompatLogger object. | ||
description: | ||
- Returns information used to create a CompatLogger object. | ||
version_added: 0.4.0 | ||
author: | ||
- Matthias Döhler <[email protected]> | ||
options: | ||
name: | ||
description: | ||
- The name of the CompatLogger object. | ||
required: true | ||
type: str | ||
state: | ||
description: | ||
- The state of the CompatLogger object. | ||
required: false | ||
default: present | ||
choices: [ "present", "absent" ] | ||
type: str | ||
order: | ||
description: | ||
- Value to determine internal precedence. | ||
required: false | ||
default: 10 | ||
type: int | ||
file: | ||
description: | ||
- Path to the file in which the object will be defined. | ||
required: true | ||
default: "features-available/compatlog.conf" | ||
type: str | ||
log_dir: | ||
description: | ||
- Path to the compat log directory. | ||
required: false | ||
type: str | ||
rotation_method: | ||
description: | ||
- Specifies when to rotate log files. | ||
required: false | ||
choices: [ "hourly", "daily", "weekly", "monthly" ] | ||
type: str | ||
''' | ||
|
||
EXAMPLES = ''' | ||
icinga.icinga.icinga2_compatlogger: | ||
name: "mycompatlogger" | ||
log_dir: "LogDir + /compat" | ||
rotation_method: "monthly" | ||
''' | ||
|
||
RETURN = ''' | ||
args: | ||
description: Arguments used to create the CompatLogger object. | ||
returned: success | ||
type: dict | ||
contains: | ||
log_dir: | ||
description: The specified log directory. | ||
returned: success | ||
type: str | ||
sample: "LogDir + /compat" | ||
rotation_method: | ||
description: The specified rotation method. | ||
returned: success | ||
type: str | ||
sample: "MONTHLY" | ||
file: | ||
description: Path to the file that will contain the object. | ||
returned: success | ||
type: str | ||
sample: features-available/compatlog.conf | ||
name: | ||
description: The name of the CompatLogger object. | ||
returned: success | ||
type: str | ||
sample: mycompatlogger | ||
order: | ||
description: The order value of this object. Used internally when combining multiple templates / objects. | ||
returned: success | ||
type: int | ||
sample: 10 | ||
state: | ||
description: The chosen state for the object. | ||
returned: success | ||
type: str | ||
sample: present | ||
''' | ||
|
||
def main(): | ||
module = AnsibleModule( | ||
supports_check_mode=True, | ||
argument_spec=dict( | ||
state=dict(default='present', choices=['present', 'absent']), | ||
name=dict(required=True), | ||
order=dict(default=10, type='int'), | ||
file=dict(default='features-available/compatlog.conf', type='str'), | ||
log_dir=dict(type='str'), | ||
rotation_method=dict(type='str', choices=['hourly', 'daily', 'weekly', 'monthly']), | ||
) | ||
) | ||
|
||
args = module.params | ||
name = args.pop('name') | ||
order = args.pop('order') | ||
state = args.pop('state') | ||
file = args.pop('file') | ||
|
||
# Capslock if rotation_method is set | ||
if args.get('rotation_method', None): | ||
args.update({'rotation_method': args.get('rotation_method').upper()}) | ||
|
||
module.exit_json( | ||
changed=False, | ||
args=args, | ||
name=name, | ||
order=str(order), | ||
state=state, | ||
file=file, | ||
) | ||
|
||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
|
||
- name: Feature compatlog CompatLogger object | ||
icinga.icinga.icinga2_object: | ||
name: compatlog | ||
type: CompatLogger | ||
file: features-available/compatlog.conf | ||
args: "{{ icinga2_dict_features.compatlog }}" | ||
register: result | ||
|
||
- set_fact: | ||
icinga2_local_objects: "{{ icinga2_local_objects|default([]) + [result.dest] }}" |
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