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

Feature/tags for elasticsearchwriter #10074

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

SebastianOpeni
Copy link
Contributor

Offers to add additional tags to entries written by the ElasticSearchWriter.

As discussed with Eric at the icinga summit we are submitting this feature. Please revise the code and let us know if there is something we need to improve. otherwise we would be happy for timely merge.

fixes #6837

Copy link

cla-bot bot commented Jun 7, 2024

Thank you for your pull request. Before we can look at it, you'll need to sign a Contributor License Agreement (CLA).

Please follow instructions at https://icinga.com/company/contributor-agreement to sign the CLA.

After that, please reply here with a comment and we'll verify.

Contributors that have not signed yet: @SebastianOpeni

  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Please contact us if you think this is the case.

  • If you signed the CLA as a corporation, your GitHub username may not have been submitted to us. Please reach out to the responsible person in your organization.

@icinga-probot icinga-probot bot added the area/elastic Events to Elasticsearch label Jun 7, 2024
Copy link

@ngoeddel-openi ngoeddel-openi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@SebastianOpeni
Copy link
Contributor Author

The CLA should be signed now.

@bobapple
Copy link
Member

bobapple commented Jun 7, 2024

@cla-bot check

@cla-bot cla-bot bot added the cla/signed label Jun 7, 2024
Copy link
Member

@yhabteab yhabteab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for your contribution! I've just been looking over the code changes and left some inline comments below, but haven't tested it with an Elastic/OpenSearch instance yet. Other than that, can you please rebase this against the current master to fix the GitHub actions. Thanks!

.mailmap Outdated Show resolved Hide resolved
doc/21-development.md Outdated Show resolved Hide resolved
lib/perfdata/elasticsearchwriter.hpp Outdated Show resolved Hide resolved
lib/perfdata/elasticsearchwriter.ti Outdated Show resolved Hide resolved
lib/perfdata/elasticsearchwriter.ti Outdated Show resolved Hide resolved
lib/perfdata/elasticsearchwriter.hpp Outdated Show resolved Hide resolved
lib/perfdata/elasticsearchwriter.cpp Outdated Show resolved Hide resolved
lib/perfdata/elasticsearchwriter.cpp Outdated Show resolved Hide resolved
@yhabteab yhabteab added this to the 2.15.0 milestone Sep 13, 2024
@yhabteab yhabteab added the enhancement New feature or request label Sep 13, 2024
@SebastianOpeni
Copy link
Contributor Author

Hi thanks for your review :)
I am currently working on your remarks but might have some questions beforehand.

@SebastianOpeni SebastianOpeni force-pushed the feature/tags-for-elasticsearchwriter-6837 branch from 44a55ec to 2f3c2fa Compare September 23, 2024 10:45
@SebastianOpeni
Copy link
Contributor Author

Thanks for your answers in the review.
I tried to implement everything as requested.

lib/perfdata/elasticsearchwriter.cpp Outdated Show resolved Hide resolved
lib/perfdata/elasticsearchwriter.cpp Outdated Show resolved Hide resolved
lib/perfdata/elasticsearchwriter.cpp Outdated Show resolved Hide resolved
.mailmap Outdated Show resolved Hide resolved
doc/21-development.md Outdated Show resolved Hide resolved
@yhabteab
Copy link
Member

Apart from #10074 (comment), code wise it should be fine now, I haven't tested it with a actual ElasticSearch instance though, but till I get the time, some of my colleagues might want a look at this as well.

doc/14-features.md Outdated Show resolved Hide resolved
lib/perfdata/elasticsearchwriter.cpp Outdated Show resolved Hide resolved
doc/14-features.md: correct Elasticsearch versions
Al2Klimov
Al2Klimov previously approved these changes Sep 25, 2024
Copy link
Member

@Al2Klimov Al2Klimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests

TL;DR: It works! 👍

➜  ~ curl -fsS http://127.0.0.1:9200/icinga2-2024.09.25/_search/ |python3 -mjson.tool
{
    "took": 5,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 6,
            "relation": "eq"
        },
        "max_score": 1.0,
        "hits": [
            {
                "_index": "icinga2-2024.09.25",
                "_type": "_doc",
                "_id": "pAd1KZIB9Wwi17GmLApi",
                "_score": 1.0,
                "_source": {
                    "@timestamp": "2024-09-25T15:53:07.855+0200",
                    "check_command": "hostalive",
                    "check_result.check_source": "ws-aklimov7777777.local",
                    "check_result.command": [
                        "/Users/aklimov/NET/WS/icinga2/prefix/usr/lib/nagios/plugins/check_ping",
                        "-H",
                        "127.0.0.1",
                        "-c",
                        "5000,100%",
                        "-w",
                        "3000,80%"
                    ],
                    "check_result.execution_end": "2024-09-25T15:53:07.855+0200",
                    "check_result.execution_start": "2024-09-25T15:53:07.854+0200",
                    "check_result.execution_time": 0.0009140968322753906,
                    "check_result.exit_status": 128,
                    "check_result.latency": 0.0381932258605957,
                    "check_result.output": "execvpe(/Users/aklimov/NET/WS/icinga2/prefix/usr/lib/nagios/plugins/check_ping) failed: No such file or directory<Terminated with exit code 128 (0x80).>",
                    "check_result.schedule_end": "2024-09-25T15:53:07.855+0200",
                    "check_result.schedule_start": "2024-09-25T15:53:07.816+0200",
                    "check_result.state": 3,
                    "check_result.vars_after": {
                        "attempt": 2,
                        "reachable": true,
                        "state": 3,
                        "state_type": 0
                    },
                    "check_result.vars_before": null,
                    "current_check_attempt": 2,
                    "host": "ws-aklimov7777777.local",
                    "last_hard_state": 1,
                    "last_state": 1,
                    "max_check_attempts": 3,
                    "reachable": true,
                    "state": 1,
                    "state_type": 0,
                    "tags": {
                        "a_list_of_items": [
                            "foo",
                            "bar"
                        ],
                        "custom_label": "A Custom Label",
                        "os_name": "Linux"
                    },
                    "timestamp": "2024-09-25T15:53:07.855+0200",
                    "type": "icinga2.event.checkresult"
                }
            },
            {
                "_index": "icinga2-2024.09.25",
                "_type": "_doc",
                "_id": "pQd1KZIB9Wwi17GmLApj",
                "_score": 1.0,
                "_source": {
                    "@timestamp": "2024-09-25T15:53:07.855+0200",
                    "check_command": "hostalive",
                    "check_result.check_source": "ws-aklimov7777777.local",
                    "check_result.command": [
                        "/Users/aklimov/NET/WS/icinga2/prefix/usr/lib/nagios/plugins/check_ping",
                        "-H",
                        "127.0.0.1",
                        "-c",
                        "5000,100%",
                        "-w",
                        "3000,80%"
                    ],
                    "check_result.execution_end": "2024-09-25T15:53:07.855+0200",
                    "check_result.execution_start": "2024-09-25T15:53:07.854+0200",
                    "check_result.execution_time": 0.0009140968322753906,
                    "check_result.exit_status": 128,
                    "check_result.latency": 0.0381932258605957,
                    "check_result.output": "execvpe(/Users/aklimov/NET/WS/icinga2/prefix/usr/lib/nagios/plugins/check_ping) failed: No such file or directory<Terminated with exit code 128 (0x80).>",
                    "check_result.schedule_end": "2024-09-25T15:53:07.855+0200",
                    "check_result.schedule_start": "2024-09-25T15:53:07.816+0200",
                    "check_result.state": 3,
                    "check_result.vars_after": {
                        "attempt": 2,
                        "reachable": true,
                        "state": 3,
                        "state_type": 0
                    },
                    "check_result.vars_before": null,
                    "current_check_attempt": 2,
                    "host": "ws-aklimov7777777.local",
                    "last_hard_state": 1,
                    "last_state": 1,
                    "max_check_attempts": 3,
                    "state": 1,
                    "tags": {
                        "a_list_of_items": [
                            "foo",
                            "bar"
                        ],
                        "custom_label": "A Custom Label",
                        "os_name": "Linux"
                    },
                    "timestamp": "2024-09-25T15:53:07.855+0200",
                    "type": "icinga2.event.statechange"
                }
            },
            {
                "_index": "icinga2-2024.09.25",
                "_type": "_doc",
                "_id": "pgd1KZIB9Wwi17GmLApj",
                "_score": 1.0,
                "_source": {
                    "@timestamp": "2024-09-25T15:53:10.689+0200",
                    "check_command": "disk",
                    "check_result.check_source": "ws-aklimov7777777.local",
                    "check_result.command": [
                        "/Users/aklimov/NET/WS/icinga2/prefix/usr/lib/nagios/plugins/check_disk",
                        "-c",
                        "10%",
                        "-w",
                        "20%",
                        "-X",
                        "none",
                        "-X",
                        "tmpfs",
                        "-X",
                        "sysfs",
                        "-X",
                        "proc",
                        "-X",
                        "configfs",
                        "-X",
                        "devtmpfs",
                        "-X",
                        "devfs",
                        "-X",
                        "mtmfs",
                        "-X",
                        "tracefs",
                        "-X",
                        "cgroup",
                        "-X",
                        "fuse.*",
                        "-X",
                        "fuse.gvfsd-fuse",
                        "-X",
                        "fuse.gvfs-fuse-daemon",
                        "-X",
                        "fuse.portal",
                        "-X",
                        "fuse.sshfs",
                        "-X",
                        "fdescfs",
                        "-X",
                        "overlay",
                        "-X",
                        "nsfs",
                        "-X",
                        "squashfs",
                        "-p",
                        "/"
                    ],
                    "check_result.execution_end": "2024-09-25T15:53:10.689+0200",
                    "check_result.execution_start": "2024-09-25T15:53:10.684+0200",
                    "check_result.execution_time": 0.004788875579833984,
                    "check_result.exit_status": 128,
                    "check_result.latency": 0.015203237533569336,
                    "check_result.output": "execvpe(/Users/aklimov/NET/WS/icinga2/prefix/usr/lib/nagios/plugins/check_disk) failed: No such file or directory<Terminated with exit code 128 (0x80).>",
                    "check_result.schedule_end": "2024-09-25T15:53:10.690+0200",
                    "check_result.schedule_start": "2024-09-25T15:53:10.670+0200",
                    "check_result.state": 3,
                    "check_result.vars_after": {
                        "attempt": 2,
                        "reachable": true,
                        "state": 3,
                        "state_type": 0
                    },
                    "check_result.vars_before": null,
                    "current_check_attempt": 2,
                    "host": "ws-aklimov7777777.local",
                    "last_hard_state": 3,
                    "last_state": 3,
                    "max_check_attempts": 5,
                    "reachable": true,
                    "service": "disk /",
                    "state": 3,
                    "state_type": 0,
                    "tags": {
                        "a_list_of_items": [
                            "foo",
                            "bar"
                        ],
                        "custom_label": "A Custom Label",
                        "os_name": "Linux",
                        "sv_name": "disk /"
                    },
                    "timestamp": "2024-09-25T15:53:10.689+0200",
                    "type": "icinga2.event.checkresult"
                }
            },
            {
                "_index": "icinga2-2024.09.25",
                "_type": "_doc",
                "_id": "pwd1KZIB9Wwi17GmLApj",
                "_score": 1.0,
                "_source": {
                    "@timestamp": "2024-09-25T15:53:10.689+0200",
                    "check_command": "disk",
                    "check_result.check_source": "ws-aklimov7777777.local",
                    "check_result.command": [
                        "/Users/aklimov/NET/WS/icinga2/prefix/usr/lib/nagios/plugins/check_disk",
                        "-c",
                        "10%",
                        "-w",
                        "20%",
                        "-X",
                        "none",
                        "-X",
                        "tmpfs",
                        "-X",
                        "sysfs",
                        "-X",
                        "proc",
                        "-X",
                        "configfs",
                        "-X",
                        "devtmpfs",
                        "-X",
                        "devfs",
                        "-X",
                        "mtmfs",
                        "-X",
                        "tracefs",
                        "-X",
                        "cgroup",
                        "-X",
                        "fuse.*",
                        "-X",
                        "fuse.gvfsd-fuse",
                        "-X",
                        "fuse.gvfs-fuse-daemon",
                        "-X",
                        "fuse.portal",
                        "-X",
                        "fuse.sshfs",
                        "-X",
                        "fdescfs",
                        "-X",
                        "overlay",
                        "-X",
                        "nsfs",
                        "-X",
                        "squashfs",
                        "-p",
                        "/"
                    ],
                    "check_result.execution_end": "2024-09-25T15:53:10.689+0200",
                    "check_result.execution_start": "2024-09-25T15:53:10.684+0200",
                    "check_result.execution_time": 0.004788875579833984,
                    "check_result.exit_status": 128,
                    "check_result.latency": 0.015203237533569336,
                    "check_result.output": "execvpe(/Users/aklimov/NET/WS/icinga2/prefix/usr/lib/nagios/plugins/check_disk) failed: No such file or directory<Terminated with exit code 128 (0x80).>",
                    "check_result.schedule_end": "2024-09-25T15:53:10.690+0200",
                    "check_result.schedule_start": "2024-09-25T15:53:10.670+0200",
                    "check_result.state": 3,
                    "check_result.vars_after": {
                        "attempt": 2,
                        "reachable": true,
                        "state": 3,
                        "state_type": 0
                    },
                    "check_result.vars_before": null,
                    "current_check_attempt": 2,
                    "host": "ws-aklimov7777777.local",
                    "last_hard_state": 3,
                    "last_state": 3,
                    "max_check_attempts": 5,
                    "service": "disk /",
                    "state": 3,
                    "tags": {
                        "a_list_of_items": [
                            "foo",
                            "bar"
                        ],
                        "custom_label": "A Custom Label",
                        "os_name": "Linux",
                        "sv_name": "disk /"
                    },
                    "timestamp": "2024-09-25T15:53:10.689+0200",
                    "type": "icinga2.event.statechange"
                }
            },
            {
                "_index": "icinga2-2024.09.25",
                "_type": "_doc",
                "_id": "qAd1KZIB9Wwi17GmLApj",
                "_score": 1.0,
                "_source": {
                    "@timestamp": "2024-09-25T15:53:15.753+0200",
                    "check_command": "ping4",
                    "check_result.check_source": "ws-aklimov7777777.local",
                    "check_result.command": [
                        "/Users/aklimov/NET/WS/icinga2/prefix/usr/lib/nagios/plugins/check_ping",
                        "-4",
                        "-H",
                        "127.0.0.1",
                        "-c",
                        "200,15%",
                        "-w",
                        "100,5%"
                    ],
                    "check_result.execution_end": "2024-09-25T15:53:15.753+0200",
                    "check_result.execution_start": "2024-09-25T15:53:15.750+0200",
                    "check_result.execution_time": 0.002724885940551758,
                    "check_result.exit_status": 128,
                    "check_result.latency": 0.012976884841918945,
                    "check_result.output": "execvpe(/Users/aklimov/NET/WS/icinga2/prefix/usr/lib/nagios/plugins/check_ping) failed: No such file or directory<Terminated with exit code 128 (0x80).>",
                    "check_result.schedule_end": "2024-09-25T15:53:15.755+0200",
                    "check_result.schedule_start": "2024-09-25T15:53:15.739+0200",
                    "check_result.state": 3,
                    "check_result.vars_after": {
                        "attempt": 2,
                        "reachable": true,
                        "state": 3,
                        "state_type": 0
                    },
                    "check_result.vars_before": null,
                    "current_check_attempt": 2,
                    "host": "ws-aklimov7777777.local",
                    "last_hard_state": 3,
                    "last_state": 3,
                    "max_check_attempts": 5,
                    "reachable": true,
                    "service": "ping4",
                    "state": 3,
                    "state_type": 0,
                    "tags": {
                        "a_list_of_items": [
                            "foo",
                            "bar"
                        ],
                        "custom_label": "A Custom Label",
                        "os_name": "Linux",
                        "sv_name": "ping4"
                    },
                    "timestamp": "2024-09-25T15:53:15.753+0200",
                    "type": "icinga2.event.checkresult"
                }
            },
            {
                "_index": "icinga2-2024.09.25",
                "_type": "_doc",
                "_id": "qQd1KZIB9Wwi17GmLApj",
                "_score": 1.0,
                "_source": {
                    "@timestamp": "2024-09-25T15:53:15.753+0200",
                    "check_command": "ping4",
                    "check_result.check_source": "ws-aklimov7777777.local",
                    "check_result.command": [
                        "/Users/aklimov/NET/WS/icinga2/prefix/usr/lib/nagios/plugins/check_ping",
                        "-4",
                        "-H",
                        "127.0.0.1",
                        "-c",
                        "200,15%",
                        "-w",
                        "100,5%"
                    ],
                    "check_result.execution_end": "2024-09-25T15:53:15.753+0200",
                    "check_result.execution_start": "2024-09-25T15:53:15.750+0200",
                    "check_result.execution_time": 0.002724885940551758,
                    "check_result.exit_status": 128,
                    "check_result.latency": 0.012976884841918945,
                    "check_result.output": "execvpe(/Users/aklimov/NET/WS/icinga2/prefix/usr/lib/nagios/plugins/check_ping) failed: No such file or directory<Terminated with exit code 128 (0x80).>",
                    "check_result.schedule_end": "2024-09-25T15:53:15.755+0200",
                    "check_result.schedule_start": "2024-09-25T15:53:15.739+0200",
                    "check_result.state": 3,
                    "check_result.vars_after": {
                        "attempt": 2,
                        "reachable": true,
                        "state": 3,
                        "state_type": 0
                    },
                    "check_result.vars_before": null,
                    "current_check_attempt": 2,
                    "host": "ws-aklimov7777777.local",
                    "last_hard_state": 3,
                    "last_state": 3,
                    "max_check_attempts": 5,
                    "service": "ping4",
                    "state": 3,
                    "tags": {
                        "a_list_of_items": [
                            "foo",
                            "bar"
                        ],
                        "custom_label": "A Custom Label",
                        "os_name": "Linux",
                        "sv_name": "ping4"
                    },
                    "timestamp": "2024-09-25T15:53:15.753+0200",
                    "type": "icinga2.event.statechange"
                }
            }
        ]
    }
}
➜  ~

Copy link
Member

@yhabteab yhabteab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this today with ElasticSearch 7.17.25 and it seems to be working fine 👍🏼. Though , whilst going through the changes again, I just noticed two small things, see inline comments below.

Edit: While you're at it, please rebase this against the master branch to get the GHAs pass.

Comment on lines +403 to +415
```
host_tags_template = {
os_name = "$host.vars.os$"
custom_label = "A Custom Label"
a_list_of_items = [ "foo", "bar" ]
}
```
Will in addition to the above mentioned lines also contain:
```
os_name = "Linux"
custom_label = "A Custom Label"
a_list_of_items = [ "foo", "bar" ]
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate to come off as nit-picky :), but instead of a_list_of_items I would just use list for the label and also add an example that you can also use macros from within the [ "$host.groups$", "$host.vars.testing$" ] brackets. Apart from that, I would also add an empty line before the opening and after the closing backticks.

Comment on lines +141 to +148
Dictionary::Ptr tmpl;
if (service) {
if (GetServiceTagsTemplate()) {
tmpl = static_pointer_cast<Dictionary>(GetServiceTagsTemplate()->ShallowClone());
}
} else if (GetHostTagsTemplate()) {
tmpl = static_pointer_cast<Dictionary>(GetHostTagsTemplate()->ShallowClone());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, after checking this for a second time, I'm wondering why you need the casting and cloning here? I would just set tmp directly to a host or service template using a conditional operator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/elastic Events to Elasticsearch cla/signed enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support host and service templates to send variables to Elasticsearch
6 participants