Icinga / icinga2

The core of our monitoring platform with a powerful configuration language and REST API.
https://icinga.com/docs/icinga2/latest
GNU General Public License v2.0
2.03k stars 578 forks source link

[dev.icinga.com #9584] Incorrect return value for the macro() function #3134

Closed icinga-migration closed 9 years ago

icinga-migration commented 9 years ago

This issue has been migrated from Redmine: https://dev.icinga.com/issues/9584

Created by roji on 2015-07-08 10:58:38 +00:00

Assignee: gbeutner Status: Resolved (closed on 2015-07-13 06:26:33 +00:00) Target Version: 2.3.7 Last Update: 2015-07-16 08:30:03 +00:00 (in Redmine)

Icinga Version: 2.3.5
Backport?: Already backported
Include in Changelog: 1

(originally posted as a question to icinga-users, received response for Michael Friedrich)

My check looks like this:

object Service "mydb" {
  import "generic-service"
  host_name = "somehost.mycompany.com"
  check_command = "postgres"
  vars.postgres_host = "somehost.mycompany.com"
  vars.postgres_dbname = "catalog"
  vars.postgres_dbuser = "mon"
  vars.postgres_dbpass = "mon"
  vars.postgres_action = "connection"
}

This check generates the error "Peer authentication failed for user "mon"", which after some digging is the result of the lack of a -H (host) parameter to check_postgres.pl. Note that in /usr/share/icinga2/include/plugins-contrib.d/databases.conf the CheckCommand object includes "vars.postgres_unixsocket = false", and the -H argument has "set_if = {{ macro("$postgres_unixsocket$") == false }}". Since I haven't defined postgres_unixsocket to be true (or anything else) the expectation is for the -H to be passed, but this doesn't happen.

This seems to be because macro("$postgres_unixsocket$") always returns a String although $postgres_unixsocket$ is a Boolean.

Changesets

2015-07-13 06:25:19 +00:00 by (unknown) 8dedd47b89639959f40d7544877bf22a052cd4af

Fix incorrect return value for the macro() function

fixes #9584

2015-07-13 06:26:17 +00:00 by (unknown) c2da4869a61620ad1636d405cda54c57cf4c7368

Fix incorrect return value for the macro() function

fixes #9584
icinga-migration commented 9 years ago

Updated by mfriedrich on 2015-07-09 08:32:51 +00:00

https://lists.icinga.org/pipermail/icinga-users/2015-June/009733.html

icinga-migration commented 9 years ago

Updated by mfriedrich on 2015-07-09 08:33:15 +00:00

Probably a bug in the macro() function.

icinga-migration commented 9 years ago

Updated by gbeutner on 2015-07-13 06:09:26 +00:00

icinga-migration commented 9 years ago

Updated by gbeutner on 2015-07-13 06:16:48 +00:00

The underlying problem is that the macro code resolves your macro like this:

  1. Look up the value of the 'postgres_unixsocket' custom variable. This yields a boolean value.
  2. Coerce the result to a string and look for more macros in that string (we support nested macros).

There's already a special case for Array objects and I guess it would make sense to expand that to include all other scalar non-string values (i.e. numbers and booleans).

icinga-migration commented 9 years ago

Updated by Anonymous on 2015-07-13 06:26:33 +00:00

Applied in changeset 8dedd47b89639959f40d7544877bf22a052cd4af.

icinga-migration commented 9 years ago

Updated by gbeutner on 2015-07-13 06:26:57 +00:00

icinga-migration commented 9 years ago

Updated by mfriedrich on 2015-07-15 08:32:11 +00:00

icinga-migration commented 9 years ago

Updated by roji on 2015-07-16 08:30:03 +00:00

Thanks, I can confirm the problem is gone in 2.3.7!