sensu / sensu-email-handler

Sensu Go Email Handler Plugin
https://sensu.io
MIT License
11 stars 17 forks source link

toEmail annotation array and quotation handling #52

Open Gillingham opened 4 years ago

Gillingham commented 4 years ago

I'm using ansible and the sensu-go-ansible playbooks to configure checks. As a result if I pass an array to the toEmail annotation it ends up being configured as ['foo@email.com', 'bar@email.com'] which sensu-email-handler accepts, and then doesnt actually send email.

A quick test of variations of quoting below:

No quotes in the array

curl -X POST -H 'Content-Type: application/json' -d '{
  "check": {
    "metadata": {
      "name": "test-event",
      "annotations": {
        "sensu.io/plugins/email/config/toEmail": "[foo@bar.com]"
      }
    },
    "status": 2,
    "output": "no quote test",
    "handlers": [ "email" ]
  }
}' http://127.0.0.1:3031/events

Results: no email

Single quote in the array

curl -X POST -H 'Content-Type: application/json' -d '{
  "check": {
    "metadata": {
      "name": "test-event",
      "annotations": {
        "sensu.io/plugins/email/config/toEmail": "['foo@bar.com']"
      }
    },
    "status": 2,
    "output": "single quote test",
    "handlers": [ "email" ]
  }
}' http://127.0.0.1:3031/events

Results: no email

Escaped double quotes

curl -X POST -H 'Content-Type: application/json' -d '{
  "check": {
    "metadata": {
      "name": "test-event",
      "annotations": {
        "sensu.io/plugins/email/config/toEmail": "[\"foo@bar.com\"]"
      }
    },
    "status": 2,
    "output": "escaped double quotes test",
    "handlers": [ "email" ]
  }
}' http://127.0.0.1:3031/events

Results: email actually sent

Any advice here? I'm not entirely sure if this is a bug here, or something to be taken up with sensu-go-ansible

nixwiz commented 4 years ago

The annotation is meant to directly override the command line argument toEmail which accepts a comma separated list of addresses.

Gillingham commented 4 years ago

That doesnt seem to be a direct passing the CLI in the case of array handling though since it will unpack an escaped double quoted array.