Skip to main content
Solved

Event handler to activate an Acknowledge

  • July 5, 2022
  • 9 replies
  • 301 views

pierre1
Forum|alt.badge.img+9

Hello Community !
Here is the configuration I'm tryuing to apply, in order to acknowledge an alert.
In this example, the topic is to create the acknowledge when the traffic on interface Tu30 is greater than 0.1%.

1-
The CLAPI command to execute is the following.

centreon -u admin -p xxx -o RTACKNOWLEDGEMENT -a add -v "SVC;RouterName,Traffic-Tu30;ACK test;2;0;1"

When I'm trying directly this command on the central, it works fine.

2-
So, I've created the following script, called handle-acknowledge-test, in /usr/lib/centreon/plugins/eventhandler/ directory
#!/bin/bash
#script to acknowledge WARNING status on RouterName host, Traffic-Tu30 service
case "$1" in
                CRITICAL)
                                ;;
                WARNING)
                 centreon -u admin -p xxx -o RTACKNOWLEDGEMENT -a add -v "SVC;RouterName,Traffic-Tu30;ACK test;2;0;1";;
                UNKNOWN)
                                ;;
                OK)
                                ;;
esac
exit 0

Rights are described here :
# ls -l | grep handle-acknowledge-test
-rwxr-xr-x 1 centreon centreon 304 Jul  5 07:48 handle-acknowledge-test

3-
The command handle-acknowledge-test has been created (Configuration  >  Commands  >  Checks)
Command Type = "Check"
$CENTREONPLUGINS$/eventhandler/handle-acknowledge-test.sh $SERVICESTATETYPE$

4-
Event handler has been configured :
Configuration  >  Pollers  >  Engine configuration, tab Check Options, Event Handler Option="Yes"
Configuration  >  Services  >  Services by host, tab Data Processing, Event Handler Enabled="Yes", Event Handler="handle-acknowledge-test"

5-
But finally, the acknowledge is not activated when the service is on warning, in spite of the following results on logs :
# tail -f /var/log/centreon-engine/centengine.log
[1657003966] [521] SERVICE ALERT: RouterName;Traffic-Tu30;WARNING;SOFT;1;WARNING: Interface 'Tu30.39%)
[1657003966] [521] SERVICE EVENT HANDLER: RouterName;Traffic-Tu30;WARNING;SOFT;1;handle-acknowled

If someone can help me at this point, it should be nice. And if finally it works, I'll create a topic with screenshot on The Watch to share this experience.

Best answer by sims24

If you can enable the debug in centeon-engine config and catch the trace of the event handler exec it could help. 

9 replies

kduret
Centreonian
Forum|alt.badge.img+10
  • Centreonian
  • July 5, 2022

Hi !

$SERVICESTATETYPE$ meens SOFT or HARD, not the status name.

You can try to replace it in check command by $SERVICESTATE$


pierre1
Forum|alt.badge.img+9
  • Author
  • July 5, 2022

Thanks, you’re right ; I’ve corrected it.

 

Unfortunately, the result is the same, the acknowledge is not activated.


sims24
Forum|alt.badge.img+19
  • Ranger ***
  • July 5, 2022

Hi, 

 

Try specify the full path to the centreon command. 


Also, when testing your script manually, do it under the centreon-engine user and not root, is this what you’ve done?


pierre1
Forum|alt.badge.img+9
  • Author
  • July 5, 2022

Hi sims24,

  • To add the full path doesn't change the result.
  • I've tried the command, manually, with centreon-engine, and the acknowledge is activated.

Using username "centreon-engine".

Last login: Tue Jul  5 12:07:55 2022
-bash-4.2$ /usr/share/centreon/bin/centreon -u admin -p xxx -o RTACKNOWLEDGEMENT -a add -v "SVC;RouterName,Traffic-Tu30;ACK test;2;0;1"

 

Do I have to modify the user/group on the file ?

# ls -l | grep handle-acknowledge-test
-rwxr-xr-x 1 centreon centreon 304 Jul  5 07:48 handle-acknowledge-test


sims24
Forum|alt.badge.img+19
  • Ranger ***
  • Answer
  • July 5, 2022

If you can enable the debug in centeon-engine config and catch the trace of the event handler exec it could help. 


pierre1
Forum|alt.badge.img+9
  • Author
  • July 5, 2022

Thanks sims24, I’ll try and keep you informed.


pierre1
Forum|alt.badge.img+9
  • Author
  • July 5, 2022

Hello, I don’t know how to activate logs for centreon-engine config, pergapes you can help me for that ?

 

But anyway, I’ve looked for data on mariadb (database centreon_storage, table eventhandlers).

Here are the last records I’ve found.

MariaDB [centreon_storage]> select * from eventhandlers where start_time>=1657027391;
+-----------------+---------+------------+------------+--------------+---------------------------------------------------------------------------+---------------+------------+----------------+--------+-------------+-------+------------+---------+------+
| eventhandler_id | host_id | service_id | start_time | command_args | command_line                                                              | early_timeout | end_time   | execution_time | output | return_code | state | state_type | timeout | type |
+-----------------+---------+------------+------------+--------------+---------------------------------------------------------------------------+---------------+------------+----------------+--------+-------------+-------+------------+---------+------+
|             107 |      74 |       1087 | 1657027391 |              | /usr/lib/centreon/plugins/eventhandler/handle-acknowledge-test.sh WARNING |             0 | 1657027391 |              0 |        |           3 |     1 |          0 |      30 |    1 |
|             109 |      74 |       1087 | 1657027451 |              | /usr/lib/centreon/plugins/eventhandler/handle-acknowledge-test.sh WARNING |             0 | 1657027451 |              0 |        |           3 |     1 |          0 |      30 |    1 |
|             111 |      74 |       1087 | 1657027511 |              | /usr/lib/centreon/plugins/eventhandler/handle-acknowledge-test.sh WARNING |             0 | 1657027511 |              0 |        |           3 |     1 |          1 |      30 |    1 |
+-----------------+---------+------------+------------+--------------+---------------------------------------------------------------------------+---------------+------------+----------------+--------+-------------+-------+------------+---------+------+
3 rows in set (0.000 sec)
 

The point is return_code=3 ; do you know the meaning of this value ?

Also, there is no output. So it seems the script is not executed.


pierre1
Forum|alt.badge.img+9
  • Author
  • July 5, 2022

Here is the mariadb extraction in a easiest format to read

 


pierre1
Forum|alt.badge.img+9
  • Author
  • August 29, 2022

Hello,

this time the issue is fixed ! 😀

The reason is here :

 

 

The name of the script was not the good one : handle-acknowledge-test instead of handle-acknowledge-test.sh

It was also necesary to provide correct rights to centreon-engine account.

Thanks to the community for your help, hoping this experience was helpful for some of you.