Behaviour of repeat_key with nested arrays
I'm building a check plugin for arbitrary elasticsearch queries.
The syntax allows to add match clauses to the query by allowing a repeated parameter in the following syntax: -m "first_field" "value" -m "second_field" "another value"
Basically it's a two-dimensional array consisting of a number of field:value pairs.
My goal was to use a nested array in the service config and the repeat_key command argument option.
command:
object CheckCommand "check_elasticsearch_query" {
import "plugin-check-command"
command = [ PluginDir + "/check_elasticsearch_query" ]
arguments += {
...
"-m" = {
repeat_key = true
value = "$elasticsearch_match$"
}
...
}
}
service template:
template Service "ES Query" {
...
vars.elasticsearch_match = [
[ "first_field", "value" ],
[ "second_field", "another value" ]
]
...
}
Expected Behavior
When calling the plugin from the command line using the syntax mentioned above, dumping the arguments (using Python's argparser) results in this:
match=[['first_field', 'value'], ['second_field', 'another value']]
I would expect the following to show up in the debug log:
'-m' 'first_field' 'value' '-m' 'second_field' 'another value'
Current Behavior
Using the template and command definition from above and calling the plugin from Icinga 2, the following arguments are dumped:
match=[['[ "first_field", "value" ]'], ['[ "second_field", "another value" ]']]
The debug log shows, that the array's second dimension is rendered like it's a string:
'-m' '[ "first_field", "value" ]' '-m' '[ "second_field", "another value" ]'
Posible Solution
Change the way the second dimension is rendered
Steps to Reproduce (for bugs)
Apply the config above
Your Environment
- Version used (
icinga2 --version): 2.8.4 - Operating System and version: Debian 9.4
- Enabled features (
icinga2 feature list): api checker ido-mysql influxdb mainlog notification - Icinga Web 2 version and modules (System - About): 2.5.3
- Config validation (
icinga2 daemon -C):
~# icinga2 daemon -C
[2018-06-20 16:13:56 +0200] warning/icinga-app: Sysconfig file '/etc/sysconfig/icinga2' cannot be read. Using default values.
[2018-06-20 16:13:56 +0200] warning/icinga-app: Sysconfig file '/etc/sysconfig/icinga2' cannot be read. Using default values.
information/cli: Icinga application loader (version: r2.8.4-1)
information/cli: Loading configuration file(s).
information/ConfigItem: Committing config item(s).
information/ApiListener: My API identity: ***
warning/ApplyRule: Apply rule 'MSSQL Workhours Host Notification' (in /var/lib/icinga2/api/zones/master/director/notification_apply.conf: 87:1-87:62) for type 'Notification' does not match anywhere!
warning/ApplyRule: Apply rule 'App - Logstash Health' (in /var/lib/icinga2/api/zones/director-global/director/service_apply.conf: 206:1-206:37) for type 'Service' does not match anywhere!
warning/ApplyRule: Apply rule 'App - Elasticsearch Health' (in /var/lib/icinga2/api/zones/director-global/director/service_apply.conf: 222:1-222:42) for type 'Service' does not match anywhere!
warning/ApplyRule: Apply rule 'System - Disk ' (in /var/lib/icinga2/api/zones/director-global/director/service_apply.conf: 564:1-564:74) for type 'Service' does not match anywhere!
warning/ApplyRule: Apply rule 'App - Webserver ' (in /var/lib/icinga2/api/zones/director-global/director/service_apply.conf: 645:1-645:73) for type 'Service' does not match anywhere!
warning/ApplyRule: Apply rule 'App - SAS Service Lev2 Metadata Server' (in /var/lib/icinga2/api/zones/director-global/director/service_apply.conf: 706:1-706:54) for type 'Service' does not match anywhere!
warning/ApplyRule: Apply rule 'App - SAS Service Lev3 Metadata Server' (in /var/lib/icinga2/api/zones/director-global/director/service_apply.conf: 714:1-714:54) for type 'Service' does not match anywhere!
warning/ApplyRule: Apply rule 'App - SAS Service Lev4 Metadata Server' (in /var/lib/icinga2/api/zones/director-global/director/service_apply.conf: 722:1-722:54) for type 'Service' does not match anywhere!
warning/ApplyRule: Apply rule 'App - SAS Service Lev2 Environment Manager Agent' (in /var/lib/icinga2/api/zones/director-global/director/service_apply.conf: 738:1-738:64) for type 'Service' does not match anywhere!
warning/ApplyRule: Apply rule 'App - SAS Service Lev3 Environment Manager Agent' (in /var/lib/icinga2/api/zones/director-global/director/service_apply.conf: 746:1-746:64) for type 'Service' does not match anywhere!
warning/ApplyRule: Apply rule 'App - SAS Service Lev4 Environment Manager Agent' (in /var/lib/icinga2/api/zones/director-global/director/service_apply.conf: 754:1-754:64) for type 'Service' does not match anywhere!
information/ConfigItem: Instantiated 1 ApiListener.
information/ConfigItem: Instantiated 59 Zones.
information/ConfigItem: Instantiated 58 Endpoints.
information/ConfigItem: Instantiated 1 FileLogger.
information/ConfigItem: Instantiated 1 ApiUser.
information/ConfigItem: Instantiated 364 Notifications.
information/ConfigItem: Instantiated 4 NotificationCommands.
information/ConfigItem: Instantiated 235 CheckCommands.
information/ConfigItem: Instantiated 26 Downtimes.
information/ConfigItem: Instantiated 15 HostGroups.
information/ConfigItem: Instantiated 1 IcingaApplication.
information/ConfigItem: Instantiated 60 Hosts.
information/ConfigItem: Instantiated 50 Comments.
information/ConfigItem: Instantiated 120 Dependencies.
information/ConfigItem: Instantiated 4 Users.
information/ConfigItem: Instantiated 2 TimePeriods.
information/ConfigItem: Instantiated 1064 Services.
information/ConfigItem: Instantiated 1 InfluxdbWriter.
information/ConfigItem: Instantiated 1 NotificationComponent.
information/ConfigItem: Instantiated 1 IdoMysqlConnection.
information/ConfigItem: Instantiated 1 CheckerComponent.
information/ScriptGlobal: Dumping variables to file '/var/cache/icinga2/icinga2.vars'
information/cli: Finished validating the configuration file(s).
Nested arrays are not supported atm. Feel free to look into a possible patch.
This would be interesting for us as well, not possible for us to code it however :|
Hi, please look into Json.encode and parse the nested message structure in your plugin. For the Icinga DSL and macro resolver this is too complicated to support.
Cheers, Henrik