Quantcast
Channel: Sensu Community - Latest posts
Viewing all articles
Browse latest Browse all 160

How to configure the email alert (SMTP config) while exit 2 code (error occured) for service check

$
0
0

I Created a simple service check bash script in all the agents in /opt/sensu/ path
service check script is an example to test the SMTP config for exit code

#!/bin/bash

# Check if nginx service is running
if systemctl is-active --quiet nginx; then
    echo "nginx service is running"
    exit 0  # Exit with status code 0 indicating OK
else
    echo "nginx service is not running"
    exit 2  # Exit with status code 2 indicating Critical
fi

from workstation i apply below yaml for creating checks and add the email-handler for sending the alerts to email

sensuctl create -f nginx_check.yml
api_version: core/v2
type: CheckConfig
metadata:
  name: nginx-check
  namespace: default
spec:
  command: "/opt/sensu/nginx_check.sh"
  subscriptions:
    - system_test
  interval: 5
  publish: true
  handlers:
  - email-handler

then i created email_handler.yaml for the same

sensuctl create -f email_handler.yaml
api_version: core/v2
type: Handler
metadata:
  name: email-handler
  namespace: default
spec:
  type: pipe
  command: "sensu-email-handler --authMethod 'none' \
--mail-from='xxxx@xxxxx.com' --mail-to='yyyy@yyyyy.com' \
--smtp-address='xx.xx.xx.xx' --smtp-port=25"
  timeout: 5
  runtime_assets:
    - email-handler

and added the plugins

sensuctl asset add sensu/sensu-email-handler -r email-handler

so can anyone tell me what addtional steps needs to be done in agent or workstation or in backend for the same
any


Viewing all articles
Browse latest Browse all 160

Trending Articles