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 object and feature for CompatLogger #351

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/feature_add_compatlogger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- Add object :code:`CompatLogger` and feature :code:`compatlog`.
1 change: 1 addition & 0 deletions doc/role-icinga2/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Current supported features:

* [Feature API](features/feature-api.md)
* [Feature Command](features/feature-command.md)
* [Feature CompatLog](features/feature-compatlog.md)
* [Feature ElasticSearch](features/feature-elasticsearch.md)
* [Feature GelfWriter](features/feature-gelf.md)
* [Feature Graphite](features/feature-graphite.md)
Expand Down
22 changes: 22 additions & 0 deletions doc/role-icinga2/features/feature-compatlog.md
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
12 changes: 12 additions & 0 deletions doc/role-icinga2/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,18 @@ icinga2_objects:
set_if: $http_ssl$
```

#### CompatLogger

```yaml
icinga2_objects:
[...]
- name: mycompatlogger
type: CompatLogger
file: "local.d/complog.conf"
log_dir: "LogDir + /custom_complog"
rotation_method: "hourly"
```

#### Dependency

```
Expand Down
128 changes: 128 additions & 0 deletions plugins/modules/icinga2_compatlogger.py
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()
12 changes: 12 additions & 0 deletions roles/icinga2/tasks/features/compatlog.yml
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] }}"
1 change: 1 addition & 0 deletions roles/icinga2/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ icinga2_object_types:
- ApiUser
- CheckCommand
- CheckerComponent
- CompatLogger
- Dependency
- ElasticsearchWriter
- Endpoint
Expand Down