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
Welcome to the community! Looking at your configuration, I only see one major thing that is not explicitly noted, which will be essential to consider: the agent subscription.
Sensu Subscription: Each Sensu agent must be configured with the subscription that matches one specified in your check configuration (system_test). This should be set in the agent’s configuration file or passed as a flag when starting the agent:
subscriptions:
- system_test
You may already have this set, but I don’t see it explicitly noted in the provided configuration.
You may also want to consider adding some of the Sensu built-in filtering for the email handler, like:
filters:
- is_incident
- not_silenced
The next steps are validating your (correctly) obfuscated email handler configuration and then testing. Will you let us know if you encounter any difficulties there?
One additional note: while your script seems fine, there is an asset that can accomplish the same task:
Hello @justinhenderson ,
Thank you for the clarification on the above issue, with all the pertinent details provided.
Yes i added the subscriptions to all the available agents
[root@test1 sensu]# sensuctl entity list
ID Class OS Subscriptions Last Seen
──────── ─────── ─────── ──────────────────────────────────── ────────────────────────────────
test1 agent linux system_test,webserver,entity:test1 2024-04-19 07:20:31 +0000 UTC
test2 agent linux system_test,webserver,entity:test2 2024-04-19 07:20:27 +0000 UTC
And after successfully receiving the alert, I also added the filter in handlers
Additionally, there is one thing I would like to ask you
If we are using sensu plugins to add the checks
then in command section we are using below syntax
and this
‘/opt/sensu/check_cpu_utilisation.sh’ script should be present in this path in every agent servers,
so is there any way that we can put custom script in one place and we are giving path of the scripts in that command section …
so we dont need to be put that custom scripts in every agent servers.
I’m glad to hear things are working. For your next question, adding custom scripts to each agent would be a good task for a configuration management tool. One of the significant benefits of using Sensu Assets is with one command, the binary will be installed on the agent right when it’s needed. So, one option is to use Sensu Assets where you can rather than custom scripts.
Your CPU check script can be accomplished similarly with an asset available on Bonsai.
If you’d like a more comprehensive, cross-platform performance check, consider using the Sensu System Check. This combines several checks into one, with which you can alert as you see fit: CPU, Memory, Swap, Disk, System Load, Host uptime, and Host processes. You can use all or just a few in one check, and that asset will show up on any agent with the check and subscription.
I’d recommend looking at Bonsai for more plugins that may be helpful for your needs.