-
Notifications
You must be signed in to change notification settings - Fork 578
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
base: master
Are you sure you want to change the base?
Feature/tags for elasticsearchwriter #10074
Conversation
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
The CLA should be signed now. |
@cla-bot check |
There was a problem hiding this 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!
Hi thanks for your review :) |
44a55ec
to
2f3c2fa
Compare
Thanks for your answers in the review. |
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: correct Elasticsearch versions
There was a problem hiding this 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"
}
}
]
}
}
➜ ~
There was a problem hiding this 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.
``` | ||
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" ] | ||
``` |
There was a problem hiding this comment.
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.
Dictionary::Ptr tmpl; | ||
if (service) { | ||
if (GetServiceTagsTemplate()) { | ||
tmpl = static_pointer_cast<Dictionary>(GetServiceTagsTemplate()->ShallowClone()); | ||
} | ||
} else if (GetHostTagsTemplate()) { | ||
tmpl = static_pointer_cast<Dictionary>(GetHostTagsTemplate()->ShallowClone()); | ||
} |
There was a problem hiding this comment.
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.
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