sensu / sensu-email-handler

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

Can't send email with 0.5.1 #49

Closed Gillingham closed 4 years ago

Gillingham commented 4 years ago

sensu-backend 5.19.1 sensu-email-handler 0.5.1

Handler configured with command as "sensu-email-handler -f foo@bar.com -s smtphost -P 25 -a none"

If I submit a test event to it with

curl -X POST -H 'Content-Type: application/json' -d '{
  "check": {
    "metadata": {
      "name": "test-event",
      "annotations": {
        "sensu.io/plugins/email/config/toEmail": "Efoo@bar.com"
      }
    },
    "status": 2,
    "output": "this is a test event targeting the email_ops handler",
    "handlers": [ "email" ]
  }
}' http://127.0.0.1:3031/events

I get no email, and the sensu-backend spits out:

Apr 22 03:49:57 certmon sensu-backend[16358]: {"check_name":"test-event","check_namespace":"default","component":"pipelined","entity_name":"certmon","entity_namespace":"default","filter":"not_silenced","handler":"email","level":"debug","msg":"allowing event","time":"2020-04-22T03:49:57Z","uuid":"1fc5dc0f-4e8d-4698-9d3d-63f124af2914"}
Apr 22 03:49:57 certmon sensu-backend[16358]: {"check_name":"test-event","check_namespace":"default","component":"pipelined","entity_name":"certmon","entity_namespace":"default","handler":"email","level":"info","msg":"sending event to handler","time":"2020-04-22T03:49:57Z","uuid":"1fc5dc0f-4e8d-4698-9d3d-63f124af2914"}
Apr 22 03:49:57 certmon sensu-backend[16358]: {"assets":["sensu/sensu-email-handler"],"check":"test-event","component":"pipelined","entity":"certmon","event_uuid":"1fc5dc0f-4e8d-4698-9d3d-63f124af2914","handler":"email","level":"debug","msg":"fetching assets for handler","namespace":"default","time":"2020-04-22T03:49:57Z"}
Apr 22 03:49:57 certmon sensu-backend[16358]: {"asset":"sensu/sensu-email-handler","component":"asset-manager","entity":"certmon","level":"info","msg":"asset includes builds, using builds instead of asset","time":"2020-04-22T03:49:57Z"}
Apr 22 03:49:57 certmon sensu-backend[16358]: {"asset":"sensu/sensu-email-handler","component":"asset-manager","entity":"certmon","filter":["entity.system.os == 'darwin'","entity.system.arch == 'amd64'"],"level":"debug","msg":"entity not filtered, not installing asset build","time":"2020-04-22T03:49:57Z"}
Apr 22 03:49:57 certmon sensu-backend[16358]: {"asset":"sensu/sensu-email-handler","component":"asset-manager","entity":"certmon","filter":["entity.system.os == 'darwin'","entity.system.arch == '386'"],"level":"debug","msg":"entity not filtered, not installing asset build","time":"2020-04-22T03:49:57Z"}
Apr 22 03:49:57 certmon sensu-backend[16358]: {"asset":"sensu/sensu-email-handler","component":"asset-manager","entity":"certmon","filter":["entity.system.os == 'darwin'","entity.system.arch == 'amd64'"],"level":"debug","msg":"entity not filtered, not installing asset build","time":"2020-04-22T03:49:57Z"}
Apr 22 03:49:57 certmon sensu-backend[16358]: {"asset":"sensu/sensu-email-handler","component":"asset-manager","entity":"certmon","filter":["entity.system.os == 'linux'","entity.system.arch == 'armv7'"],"level":"debug","msg":"entity not filtered, not installing asset build","time":"2020-04-22T03:49:57Z"}
Apr 22 03:49:57 certmon sensu-backend[16358]: {"asset":"sensu/sensu-email-handler","component":"asset-manager","entity":"certmon","filter":["entity.system.os == 'linux'","entity.system.arch == 'arm64'"],"level":"debug","msg":"entity not filtered, not installing asset build","time":"2020-04-22T03:49:57Z"}
Apr 22 03:49:57 certmon sensu-backend[16358]: {"asset":"sensu/sensu-email-handler","component":"asset-manager","entity":"certmon","filter":["entity.system.os == 'linux'","entity.system.arch == '386'"],"level":"debug","msg":"entity not filtered, not installing asset build","time":"2020-04-22T03:49:57Z"}
Apr 22 03:49:57 certmon sensu-backend[16358]: {"asset":"sensu/sensu-email-handler","component":"asset-manager","entity":"certmon","filter":["entity.system.os == 'linux'","entity.system.arch == 'amd64'"],"level":"debug","msg":"entity filtered, installing asset build","time":"2020-04-22T03:49:57Z"}
Apr 22 03:49:57 certmon sensu-backend[16358]: {"assets":["sensu/sensu-email-handler"],"check":"test-event","component":"pipelined","entity":"certmon","event_uuid":"1fc5dc0f-4e8d-4698-9d3d-63f124af2914","handler":"email","level":"info","msg":"event pipe handler executed","namespace":"default","output":"Usage:\n  sensu-email-handler [flags]\n  sensu-email-handler [command]\n\nAvailable Commands:\n  help        Help about any command\n  version     Print the version number of this plugin\n\nFlags:\n  -a, --authMethod string         The SMTP authentication method, one of 'none', 'plain', or 'login' (default \"plain\")\n  -T, --bodyTemplateFile string   A template file to use for the body\n  -l, --enableLoginAuth           [deprecated] Use \"login auth\" mechanisim\n  -f, --fromEmail string          The 'from' email address\n  -h, --help                      help for sensu-email-handler\n  -H, --hookout                   Include output from check hook(s)\n  -i, --insecure                  [deprecated] Use an insecure connection (unauthenticated on port 25)\n  -s, --smtpHost string           The SMTP host to use to send to send email\n  -p, --smtpPassword string       The SMTP password, if not in env SMTP_PASSWORD\n  -P, --smtpPort uint             The SMTP server port (default 587)\n  -u, --smtpUsername string       The SMTP username, if not in env SMTP_USERNAME\n  -S, --subjectTemplate string    A template to use for the subject (default \"Sensu Alert - {{.Entity.Name}}/{{.Check.Name}}: {{.Check.State}}\")\n  -k, --tlsSkipVerify             Do not verify TLS certificates\n  -t, --toEmail strings           The 'to' email address (accepts comma delimited and/or multiple flags)\n\nUse \"sensu-email-handler [command] --help\" for more information about a command.\n\nError executing sensu-email-handler: invalid character 'E' looking for beginning of value\n","status":1,"time":"2020-04-22T03:49:57Z"}
Gillingham commented 4 years ago

If I do nothing but roll back to sensu-email-handler 0.4.0 the above commands work fine.

nixwiz commented 4 years ago

In looking at this, I am certain it has to do with the recent change of the config.ToEmail from a string to a slice of strings. Something in the Sensu SDK code is choking on that when attempting to do the annotation override.

Thoughts @echlebek ?

echlebek commented 4 years ago

It does seem to be a possible culprit. I'll have to look at what the SDK is doing in this circumstance. My feeling is that since the command-line argument still works the same, that the annotations should as well.

Gillingham commented 4 years ago

Since it's been awhile, is there a work-around for this? Sending to multiple emails is something we really need so would like to be able to upgrade even if that means we have to like wrap any single emailed notifications in an array or something to get 0.5.1 working.