Rule doesn't match sensor output

(Batman) #1


I found out my rule doesn’t match with sensor output but unsure whats wrong. Any insight will be of much help

Sensor output:

2019-02-01 06:21:48,072 INFO [-] Processing event: {u'check_result': {u'check_source': u'xxx', u'exit_status': 2.0, u'vars_before': {u'state_type': 1.0, u'reachable': True, u'state': 2.0, u'attempt': 1.0}, u'type': u'CheckResult', u'vars_after': {u'state_type': 1.0, u'reachable': True, u'state': 2.0, u'attempt': 1.0}, u'execution_start': 1549002107.592814, u'schedule_end': 1549002108.066733, u'performance_data': [u'available_upgrades=3;;;0', u'critical_updates=3;;;0'], u'state': 2.0, u'command': xxx'], u'execution_end': 1549002108.066672, u'active': True, u'output': u'APT CRITICAL: xxx ', u'schedule_start': 1549002107.592504}, u'timestamp': 1549002108.066818, u'host': u'xxx', u'type': u'CheckResult', u'service': u'apt'}


name: icinga_action
pack: icinga2
description: Post to chat when icinga2 service state changes
enabled: true
  type: icinga2.event.state_change
#  trigger.type:
#    pattern: "u'state_type"
#    type: "eq"
#  trigger.state_type:
#    pattern: 0.1
#    type: gt
criteria:                              # optional
     type: "matchregex"
     pattern : "*exit_status*"
     type: "gt"
     pattern : "0.1"

  ref: chatops.post_message
    message: Icinga2 service {{trigger.service}} on host {{}} has changed its state to {{ trigger.state|int }}, state type {{ trigger.state_type|int }}
    channel: 'xxxx'

Rule Doesn’t Match:

2019-02-01 06:28:53,216 INFO [-] Validating rule icinga2.icinga_action for event.state_change.
2019-02-01 06:28:53,232 INFO [-] Validation for rule icinga2.icinga_action failed on criteria -
key: trigger.state_type
pattern: 0.1
type: gt
payload: None
2019-02-01 06:28:53,232 INFO [-] 0 rule(s) found to enforce for event.state_change.
2019-02-01 06:28:53,232 INFO [-] === RULE DOES NOT MATCH ===



Your data is not valid JSON. That is why the rule is not matching.

(Lindsay Hill) #3

Look at your trigger instance, specifically the type: parameter - it is 'type': 'CheckResult'

But in your rule, you’re doing this:

     type: "matchregex"
     pattern : "*exit_status*"

exit_status is the name of a key within your trigger - it is not a value. Are you trying to check if that key exists, or are you trying to check that the exit_status key exists, and is a particular value?

(Batman) #4

Thanks @blag, @lhill: That solved the Issue.