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

error with match and type matchany #6496

Closed
chherse opened this issue Jul 27, 2018 · 3 comments · Fixed by #6498
Closed

error with match and type matchany #6496

chherse opened this issue Jul 27, 2018 · 3 comments · Fixed by #6498
Assignees
Labels
area/configuration DSL, parser, compiler, error handling bug Something isn't working
Milestone

Comments

@chherse
Copy link

chherse commented Jul 27, 2018

I have Troubel with a strange behavior of the assign match function. After a update of the new icinga2 version 2.9.1 i get services with assign rules on host that shouldn´t get this services. I guess the reason is the showing behavior.

# icinga2 console
Icinga 2 (version: r2.9.1-1)
Type $help to view available commands.
<1> => var role = [ "wb" , "wb" ]
null
<2> => match("mail-storage", role, MatchAny)
true

I would expect a false, but the matchany give me a true.

My Environment

  • Version used (icinga2 --version):
    icinga2 --version
    icinga2 - The Icinga 2 network monitoring daemon (version: r2.9.1-1)

Copyright (c) 2012-2018 Icinga Development Team (https://www.icinga.com/)
License GPLv2+: GNU GPL version 2 or later http://gnu.org/licenses/gpl2.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Application information:
Installation root: /usr
Sysconf directory: /etc
Run directory: /run
Local state directory: /var
Package data directory: /usr/share/icinga2
State path: /var/lib/icinga2/icinga2.state
Modified attributes path: /var/lib/icinga2/modified-attributes.conf
Objects path: /var/cache/icinga2/icinga2.debug
Vars path: /var/cache/icinga2/icinga2.vars
PID path: /run/icinga2/icinga2.pid

System information:
Platform: Ubuntu
Platform version: 16.04.5 LTS (Xenial Xerus)
Kernel: Linux
Kernel version: 4.4.0-116-generic
Architecture: x86_64

Build information:
Compiler: GNU 5.3.1
Build host: 1b4c52bdc470

  • Operating System and version:
    Ubuntu 16.04.5 LTS
    Linux smon01 4.4.0-116-generic [dev.icinga.com #2728] Config: Clean up ObjectSet/ObjectMap classes #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  • Enabled features (icinga2 feature list):
    icinga2 feature list
    Disabled features: compatlog debuglog elasticsearch gelf influxdb livestatus opentsdb perfdata statusdata syslog
    Enabled features: api checker command graphite ido-mysql mainlog notification
  • Icinga Web 2 version and modules (System - About):
    IcingaWeb2 2.6
    graphite 1.0.1
    monitoring 2.6.0
    unicorn 1.0.2 [;-)]
  • Config validation (icinga2 daemon -C):
    icinga2 daemon -C
    [2018-07-27 16:06:38 +0200] information/cli: Icinga application loader (version: r2.9.1-1)
    [2018-07-27 16:06:38 +0200] information/cli: Loading configuration file(s).
    [2018-07-27 16:06:38 +0200] information/ConfigItem: Committing config item(s).
    [2018-07-27 16:06:38 +0200] information/ApiListener: My API identity: smon01.***
    [2018-07-27 16:06:45 +0200] warning/ApplyRule: Apply rule '' (in /etc/icinga2/zones.d/global-templates/services/agent.conf: 1:0-1:64) for type 'Service' does not match anywhere!
    [2018-07-27 16:06:45 +0200] warning/ApplyRule: Apply rule '' (in /etc/icinga2/zones.d/global-templates/services/http.conf: 30:1-30:52) for type 'Service' does not match anywhere!
    [2018-07-27 16:06:45 +0200] warning/ApplyRule: Apply rule 'HTTP Proxy .70 ' (in /etc/icinga2/zones.d/global-templates/services/http.conf: 46:1-46:65) for type 'Service' does not match anywhere!
    [2018-07-27 16:06:45 +0200] warning/ApplyRule: Apply rule 'HTTP Proxy .71 ' (in /etc/icinga2/zones.d/global-templates/services/http.conf: 62:1-62:65) for type 'Service' does not match anywhere!
    [2018-07-27 16:06:45 +0200] warning/ApplyRule: Apply rule 'HTTP Access ' (in /etc/icinga2/zones.d/global-templates/services/http.conf: 78:1-78:63) for type 'Service' does not match anywhere!
    [2018-07-27 16:06:45 +0200] warning/ApplyRule: Apply rule 'SSH MySQL Connection Time' (in /etc/icinga2/zones.d/global-templates/services/ssh_mysql_health.conf: 1:0-1:40) for type 'Service' does not match anywhere!
    [2018-07-27 16:06:45 +0200] warning/ApplyRule: Apply rule 'SSH MySQL Index Usage' (in /etc/icinga2/zones.d/global-templates/services/ssh_mysql_health.conf: 11:1-11:37) for type 'Service' does not match anywhere!
    [2018-07-27 16:06:45 +0200] warning/ApplyRule: Apply rule 'SSH MySQL InnoDB Bufferpool Hitrate' (in /etc/icinga2/zones.d/global-templates/services/ssh_mysql_health.conf: 21:1-21:51) for type 'Service' does not match anywhere!
    [2018-07-27 16:06:45 +0200] warning/ApplyRule: Apply rule 'SSH MySQL QCache Hitrate' (in /etc/icinga2/zones.d/global-templates/services/ssh_mysql_health.conf: 31:1-31:40) for type 'Service' does not match anywhere!
    [2018-07-27 16:06:45 +0200] warning/ApplyRule: Apply rule 'SSH MySQL Threadcache Hitrate' (in /etc/icinga2/zones.d/global-templates/services/ssh_mysql_health.conf: 41:1-41:45) for type 'Service' does not match anywhere!
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 5452 Services.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 17 ServiceGroups.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 23 ScheduledDowntimes.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 29 HostGroups.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 2 EventCommands.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 1 FileLogger.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 1 NotificationComponent.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 2 NotificationCommands.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 6088 Notifications.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 1 IcingaApplication.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 327 Hosts.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 1 ApiListener.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 46 Downtimes.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 1325 Dependencies.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 1 GraphiteWriter.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 184 Comments.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 1 CheckerComponent.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 3 Zones.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 1 ExternalCommandListener.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 2 Endpoints.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 3 ApiUsers.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 3 UserGroups.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 1 IdoMysqlConnection.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 263 CheckCommands.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 4 TimePeriods.
    [2018-07-27 16:06:45 +0200] information/ConfigItem: Instantiated 7 Users.
    [2018-07-27 16:06:45 +0200] information/ScriptGlobal: Dumping variables to file '/var/cache/icinga2/icinga2.vars'
    [2018-07-27 16:06:45 +0200] information/cli: Finished validating the configuration file(s).
  • If you run multiple Icinga 2 instances, the zones.conf file (or icinga2 object list --type Endpoint and icinga2 object list --type Zone) from all affected nodes.
    icinga2 object list --type Endpoint
    Object 'smon01.***' of type 'Endpoint':
    % declared in '/etc/icinga2/zones.conf', lines 1:0-1:45
    • __name = "smon01.***"
    • host = "smon01.***"
      % = modified in '/etc/icinga2/zones.conf', lines 2:3-2:39
    • log_duration = 86400
    • name = "smon01.***"
    • package = "_etc"
    • port = "5665"
    • source_location
      • first_column = 0
      • first_line = 1
      • last_column = 45
      • last_line = 1
      • path = "/etc/icinga2/zones.conf"
    • templates = [ "smon01.***" ]
      % = modified in '/etc/icinga2/zones.conf', lines 1:0-1:45
    • type = "Endpoint"
    • zone = ""

Object 'smon02.***' of type 'Endpoint':
% declared in '/etc/icinga2/zones.conf', lines 5:1-5:46

  • __name = "smon02.***"
  • host = "smon02.***"
    % = modified in '/etc/icinga2/zones.conf', lines 6:3-6:39
  • log_duration = 86400
  • name = "smon02.***"
  • package = "_etc"
  • port = "5665"
  • source_location
    • first_column = 1
    • first_line = 5
    • last_column = 46
    • last_line = 5
    • path = "/etc/icinga2/zones.conf"
  • templates = [ "smon02.***" ]
    % = modified in '/etc/icinga2/zones.conf', lines 5:1-5:46
  • type = "Endpoint"
  • zone = ""

icinga2 object list --type Zone
Object 'director-global' of type 'Zone':
% declared in '/etc/icinga2/zones.conf', lines 18:1-18:29

  • __name = "director-global"
  • endpoints = null
  • global = true
    % = modified in '/etc/icinga2/zones.conf', lines 19:3-19:15
  • name = "director-global"
  • package = "_etc"
  • parent = ""
  • source_location
    • first_column = 1
    • first_line = 18
    • last_column = 29
    • last_line = 18
    • path = "/etc/icinga2/zones.conf"
  • templates = [ "director-global" ]
    % = modified in '/etc/icinga2/zones.conf', lines 18:1-18:29
  • type = "Zone"
  • zone = ""

Object 'global-templates' of type 'Zone':
% declared in '/etc/icinga2/zones.conf', lines 14:1-14:30

  • __name = "global-templates"
  • endpoints = null
  • global = true
    % = modified in '/etc/icinga2/zones.conf', lines 15:3-15:15
  • name = "global-templates"
  • package = "_etc"
  • parent = ""
  • source_location
    • first_column = 1
    • first_line = 14
    • last_column = 30
    • last_line = 14
    • path = "/etc/icinga2/zones.conf"
  • templates = [ "global-templates" ]
    % = modified in '/etc/icinga2/zones.conf', lines 14:1-14:30
  • type = "Zone"
  • zone = ""

Object 'master' of type 'Zone':
% declared in '/etc/icinga2/zones.conf', lines 9:1-9:20

  • __name = "master"
  • endpoints = [ "smon01***", "smon02.***" ]
    % = modified in '/etc/icinga2/zones.conf', lines 10:3-10:80
  • global = false
  • name = "master"
  • package = "_etc"
  • parent = ""
  • source_location
    • first_column = 1
    • first_line = 9
    • last_column = 20
    • last_line = 9
    • path = "/etc/icinga2/zones.conf"
  • templates = [ "master" ]
    % = modified in '/etc/icinga2/zones.conf', lines 9:1-9:20
  • type = "Zone"
  • zone = ""

Is this a bug or a failure on my site?

@dnsmichi
Copy link
Contributor

vim eval

ar r = [ "a", "b" ]
match("c", r, MatchAny)
mbmif /usr/local/icinga2/etc/icinga2/tests (master *) # lldb -- /usr/local/icinga2/lib/icinga2/sbin/icinga2 console --file eval
(lldb) target create "/usr/local/icinga2/lib/icinga2/sbin/icinga2"
Current executable set to '/usr/local/icinga2/lib/icinga2/sbin/icinga2' (x86_64).
(lldb) settings set -- target.run-args  "console" "--file" "eval"
(lldb) r
Process 62824 launched: '/usr/local/icinga2/lib/icinga2/sbin/icinga2' (x86_64)
true
Process 62824 exited with status = 0 (0x00000000)
(lldb) b scriptutils.cpp:184
Breakpoint 1: where = icinga2`icinga::ScriptUtils::Match(std::__1::vector<icinga::Value, std::__1::allocator<icinga::Value> > const&) + 1085 at scriptutils.cpp:184, address = 0x000000010024c6ad
(lldb) r
Process 62930 launched: '/usr/local/icinga2/lib/icinga2/sbin/icinga2' (x86_64)
Process 62930 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x000000010024c6ad icinga2`icinga::ScriptUtils::Match(args=size=1) at scriptutils.cpp:184
   181 				return false;
   182
   183 			for (const String& text : texts) {
-> 184 				bool res = Utility::Match(pattern, text);
   185
   186 				if (mode == MatchAny && res)
   187 					return true;
Target 0: (icinga2) stopped.
(lldb) p text
(const icinga::String) $0 = (m_Data = "a")
(lldb) p pattern
(icinga::String) $1 = (m_Data = "c")
(lldb) n
Process 62930 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x000000010024c6d9 icinga2`icinga::ScriptUtils::Match(args=size=1) at scriptutils.cpp:186
   183 			for (const String& text : texts) {
   184 				bool res = Utility::Match(pattern, text);
   185
-> 186 				if (mode == MatchAny && res)
   187 					return true;
   188 				else if (mode == MatchAll && !res)
   189 					return false;
Target 0: (icinga2) stopped.
(lldb) p res
(bool) $2 = false
(lldb) p mode
(MatchType) $3 = MatchAny
(lldb) n
Process 62930 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x000000010024c729 icinga2`icinga::ScriptUtils::Match(args=size=1) at scriptutils.cpp:188
   185
   186 				if (mode == MatchAny && res)
   187 					return true;
-> 188 				else if (mode == MatchAll && !res)
   189 					return false;
   190 			}
   191
Target 0: (icinga2) stopped.
(lldb)
Process 62930 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x000000010024c75e icinga2`icinga::ScriptUtils::Match(args=size=1) at scriptutils.cpp:190
   187 					return true;
   188 				else if (mode == MatchAll && !res)
   189 					return false;
-> 190 			}
   191
   192 			return true;
   193 		} else {
Target 0: (icinga2) stopped.
(lldb)
Process 62930 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x000000010024c787 icinga2`icinga::ScriptUtils::Match(args=size=1) at scriptutils.cpp:183
   180 			if (texts->GetLength() == 0)
   181 				return false;
   182
-> 183 			for (const String& text : texts) {
   184 				bool res = Utility::Match(pattern, text);
   185
   186 				if (mode == MatchAny && res)
Target 0: (icinga2) stopped.
(lldb)
Process 62930 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x000000010024c6ad icinga2`icinga::ScriptUtils::Match(args=size=1) at scriptutils.cpp:184
   181 				return false;
   182
   183 			for (const String& text : texts) {
-> 184 				bool res = Utility::Match(pattern, text);
   185
   186 				if (mode == MatchAny && res)
   187 					return true;
Target 0: (icinga2) stopped.
(lldb)
Process 62930 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x000000010024c6d9 icinga2`icinga::ScriptUtils::Match(args=size=1) at scriptutils.cpp:186
   183 			for (const String& text : texts) {
   184 				bool res = Utility::Match(pattern, text);
   185
-> 186 				if (mode == MatchAny && res)
   187 					return true;
   188 				else if (mode == MatchAll && !res)
   189 					return false;
Target 0: (icinga2) stopped.
(lldb) p res
(bool) $4 = false
(lldb) p text
(const icinga::String) $5 = (m_Data = "b")
(lldb) p pattern
(icinga::String) $6 = (m_Data = "c")
(lldb) n
Process 62930 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x000000010024c729 icinga2`icinga::ScriptUtils::Match(args=size=1) at scriptutils.cpp:188
   185
   186 				if (mode == MatchAny && res)
   187 					return true;
-> 188 				else if (mode == MatchAll && !res)
   189 					return false;
   190 			}
   191
Target 0: (icinga2) stopped.
(lldb) p res
(bool) $7 = false
(lldb) p mode
(MatchType) $8 = MatchAny
(lldb) n
Process 62930 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x000000010024c75e icinga2`icinga::ScriptUtils::Match(args=size=1) at scriptutils.cpp:190
   187 					return true;
   188 				else if (mode == MatchAll && !res)
   189 					return false;
-> 190 			}
   191
   192 			return true;
   193 		} else {
Target 0: (icinga2) stopped.
(lldb)
Process 62930 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x000000010024c787 icinga2`icinga::ScriptUtils::Match(args=size=1) at scriptutils.cpp:183
   180 			if (texts->GetLength() == 0)
   181 				return false;
   182
-> 183 			for (const String& text : texts) {
   184 				bool res = Utility::Match(pattern, text);
   185
   186 				if (mode == MatchAny && res)
Target 0: (icinga2) stopped.
(lldb)
Process 62930 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x000000010024c7aa icinga2`icinga::ScriptUtils::Match(args=size=1) at scriptutils.cpp:192
   189 					return false;
   190 			}
   191
-> 192 			return true;
   193 		} else {
   194 			String text = argTexts;
   195 			return Utility::Match(pattern, argTexts);
Target 0: (icinga2) stopped.

This should return false, but drops out of the loop.

@dnsmichi
Copy link
Contributor

It is a regression from 80b72cf

@eserte
Copy link

eserte commented Nov 28, 2018

For users who cannot upgrade to 2.9.2: a possible workaround is to use Array's any method. So instead

match("something*", arr, MatchAny)

one may write

arr.any(function(e) { return match("something*", e) })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/configuration DSL, parser, compiler, error handling bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants