Handlers (email - handler) related questions - Sensu Go

Dear Team,

As we are testing Sensu for our organization, Need your help with below questions to understand sensu better.

  1. We noticed sensu mail handler only works when docker container is connected to host network .
    - is there any method/mail plugins (postfix etc) to directly send mail other than linking it to the postfix container.
  2. Email handler requires smtp connection credentials mandatory (As postfix running locally with sendmail utility we can send mails from container) is there any way credentials can be skipped(as credentials has to be updated every 2 months)
  3. Does Asset Handlers (eg. email handler ) will be downloaded in every sensu-agents to send alerts or sending mails will be taken care by sensu-backend itself(Some of our servers doesn’t have postfix installed so).
  4. Sensu Entity(agents) by default list the docker container id is there any way to give proper name or alias so that after every restart server agent name doesnt change for particular nodes.
  5. Mattermost handler plugin doesnt work - request you to suggest working mattermost plugins.
Really appreciate your help if we can get the solutions/suggestions from sensu community as we are still in learning phase :)

Thanks,
Sensu-user :slight_smile:

  1. There are several options for configuring an smtp server in docker. Ex:
    GitHub - BytemarkHosting/docker-smtp: Docker image for sending outgoing mail

I’m not sure why you are finding that the handler requires to be on the host network to work.
This sounds like docker configuration issue.

  1. Are you using this email handler: sensu-email-handler versions
    The --authMethod none cmdline argument to the handler should let you connect without credentials

  2. handlers,mutators and filters are run by one of the sensu-backends.
    Here’s a clickable depiction of the Sensu observibility pipeline that might help vizualize what does what.
    https://docs.sensu.io/sensu-go/latest/observability-pipeline/observe-process/

  3. you can set the agent name explicit as part of agent configuration… the default is whatever hostname the agent detects from the system. In the case of docker, that’s usually the container id.
    Agent name can either be set via a cmdline argument to sensu-agent start or by setting SENSU_NAME envvar passed into the container, or by configuring the name key in the agent.yml configuration file inside the container.

Which mechanism you use really comes down to preference on how you want to manage the docker container for the agent. But I’d wager setting SENSU_NAME is probably the easiest way to do if if that’s the only additional customization you need.
Basically most of the configuration options for agent are available as config file keys, commandline arguments and envvars following a similar pattern.

  1. Understood, there’s still a need to port many of the community supported handlers from Sensu Core to work with the new Sensu Go event model.
    Though, what would be really great is if a community member who uses MatterMost could write a golang based handler using the Sensu Plugin SDK. We’ve put together a tool to generate Sensu plugin projects on github that puts all the necessary boiler plate together GitHub - sensu-community/handler-plugin-template to make it really easy to get started writing a new handler.

Thanks @jspaleta for the Quality answer and quick reply.

You were correct about mail part, Issue was with host postfix configuration file - Mail is working fine without the host network.

  1. –authMethod=none is not working, are we missing something in below test command

./sensu-email-handler --help doesnt show (-a or --authMethod) options as described in github

/var/lib/sensu # sensuctl event info test-docker keepalive --format=json | ./sensu-email-handler --authMethod=none -f user@mydomain.com -t user@mydomain.com -s smtp.server.mydomain.com -P 25 -S β€˜Test mail from sensu’
Error: unknown flag: --authMethod
Usage:
sensu-email-handler [flags]

Flags:
-T, --bodyTemplateFile string A template file to use for the body
-l, --enableLoginAuth Use β€œlogin auth” mechanisim
-f, --fromEmail string The β€˜from’ email address
-h, --help help for sensu-email-handler
-H, --hookout Include output from check hook(s)
-i, --insecure Use an insecure connection (unauthenticated on port 25)
-s, --smtpHost string The SMTP host to use to send to send email
-p, --smtpPassword string The SMTP password, if not in env SMTP_PASSWORD
-P, --smtpPort uint The SMTP server port (default 587)
-u, --smtpUsername string The SMTP username, if not in env SMTP_USERNAME
-S, --subjectTemplate string A template to use for the subject (default β€œSensu Alert - {{.Entity.Name}}/{{.Check.Name}}: {{.Check.State}}”)
-t, --toEmail string The β€˜to’ email address

Error executing [sensu-email-handler unknown flag: --authMethod]: %!v(MISSING)

( Fyi: sensu-email-handler binary is kept in /var/lib/sensu and ran a test mail as above for checking. user mail and smtp addresses are random for obvious reasons )

Question: Is there any configuration option available for containers like .yml files for logging errors/warnings into a log file in particular path (docker logs contains huge logs and finding/debugging the error is difficult)

Thanks in advance.
Regards,
Sensu-user :slight_smile:

Hmm what version of that handler are you using. Maybe we need to push a new release

I just confirmed locally that the 0.9.0 release does have argument. You probably just need to update the asset to a newer version. If you installed it via sensuctl, you can do it prety easily.

Example I have a system with some old assets installed.
I can get a list of outdated Bonsai assets with:
sensuctl asset outdated

$ sensuctl asset outdated 
                Asset Name                               Bonsai Asset                 Current Version   Latest Version  
 ───────────────────────────────────────── ───────────────────────────────────────── ───────────────── ──────────────── 
  sensu-plugins/sensu-plugins-disk-checks   sensu-plugins/sensu-plugins-disk-checks   5.1.3             5.1.4           
  sensu/sensu-email-handler                 sensu/sensu-email-handler                 0.8.1             0.9.0           
  sensu/sensu-influxdb-handler              sensu/sensu-influxdb-handler              3.5.0             3.6.1           
  sensu/sensu-pagerduty-handler             sensu/sensu-pagerduty-handler             2.0.1             2.1.0           

to update the email handler to the 0.9.0 release I can do

$ sensuctl asset add sensu/sensu-email-handler:0.9.0
fetching bonsai asset: sensu/sensu-email-handler:0.9.0
added asset: sensu/sensu-email-handler:0.9.0

You have successfully added the Sensu asset resource, but the asset will not get downloaded until
it's invoked by another Sensu resource (ex. check). To add this runtime asset to the appropriate
resource, populate the "runtime_assets" field with ["sensu/sensu-email-handler"].

Now I have the latest version of the asset, and backends will be directly to download and use the new version next time the need to run the handler.

1 Like

Thanks @jspaleta , Worked like a charm :grinning:
Email-handler version was 0.2 so we weren’t getting that option, Now its fine.