
Centreon Alerts with OpenAI
Well, this post with summer style… About something we keep hearing… AI… in this post we will see how we can use OpenAI to make the notifications of our monitoring system somewhat more personalized…
Yes, As you already know, You can ask OpenAI for many things, in this case we will use it to adapt the messages that come from Centreon and perhaps make them simpler, or whatever we need. Since I'll only use it for that, so that he sends me the alert and transcribes it in a more human way. Of course, we can say that it helps us or guides us to solve it, Or that he tells us by rhyming, hip-hop, in verse, or as Chiquito de la Calzada, That's it… to taste.
Before anyone gets excited… Yes, we will need a paid OpenAI account, but the cost that this use can entail is ridiculous, in addition, we will be able to parameterize so that it uses fewer tokens, etc… About 0,05€ per day? It will depend on the number of notifications you have as well…
How do we achieve this?? Well, it's really simple, in my case I use Telegram for notifications, So I have 2 Scripts, one for Host notifications and one for Services notifications. These scripts will receive as arguments because that, the affected Host/Service, With your state, Your output… the scripts will ask OpenAI to please transcribe them in a human way if it is not too much hassle, using friendly language, close, blah, blah, to taste… or addressed to a technical department, that he would also like you to guide him… Of course, that you should customize it to your liking.
Script /usr/lib/centreon/plugins/notifica_telegram_ia_servicio.sh
#!/bin/bash text="Please, generates a text for a notification that will be sent to the user's smartphone with useful information. You're a helpful personal agent who generates text for IT technicians. Your answers are brief, Useful, Kind, Warm, Insightful. Your answers can be technical, don't offer to help you and don't include internal Home Assistant details, as entities in responses. The message you have to say is about a problem of type: $1, In the team $2 since the service $3 is in the state $4. You don't need to say hello." texto_generado=$(/usr/bin/curl https://api.openai.com/v1/completions -H "Content-Type: application/json" -H "Authorization: Bearer sk-TOKEN_OPENAI" -d '{ "model": "text-davinci-003", "prompt": "'"$text"'", "temperature": 0.9, "max_tokens": 100 }' | jq -r '.choices[0].text') texto_generado=$(ECHO "$texto_generado" | Thirst 1D) /usr/bin/curl -X POST -H "Content-Type: application/json" -d '{ "chat_id": "ID_CHAT_TELEGRAM_DESTINO", "text": "'"$texto_generado"'" }' "https://api.telegram.org/botTOKEN_TELEGRAM/sendMessage"
Script /usr/lib/centreon/plugins/notifica_telegram_ia_host.sh
#!/bin/bash text="Please, generates a text for a notification that will be sent to the user's smartphone with useful information. You're a helpful personal agent who generates text for IT technicians. Your answers are brief, Useful, Kind, Warm, Insightful. Your answers can be technical, don't offer to help you and don't include internal Home Assistant details, as entities in responses. The message you have to say is about a problem of type: $1, In the team $2 since it's in the state $3. You don't need to say hello." texto_generado=$(/usr/bin/curl https://api.openai.com/v1/completions -H "Content-Type: application/json" -H "Authorization: Bearer sk-TOKEN_OPENAI" -d '{ "model": "text-davinci-003", "prompt": "'"$text"'", "temperature": 0.9, "max_tokens": 100 }' | jq -r '.choices[0].text') texto_generado=$(ECHO "$texto_generado" | Thirst 1D) /usr/bin/curl -X POST -H "Content-Type: application/json" -d '{ "chat_id": "ID_CHAT_TELEGRAM_DESTINO", "text": "'"$texto_generado"'" }' "https://api.telegram.org/botTOKEN_TELEGRAM/sendMessage"
Once the scripts are saved (remember to make them executable), we can now go to the Centreon GUI and create a Notification Command, for this, We're going to “Configuration” > “Commands” > “Notifications”, We will create two, one for the Services and one for the Hosts.
The command called 'Telegram_servicios_IA_sh’ has the following command line:
/usr/lib/centreon/plugins/notifica_telegram_ia_servicio.sh '$SERVICESTATE$' \ '$HOSTNAME$' \ '$SERVICEDESC$' \ '$SERVICEOUTPUT$'
The command called 'Telegram_hosts_IA_sh’ has the following command line:
/usr/lib/centreon/plugins/notifica_telegram_ia_host.sh '$HOSTSTATE$' \ '$HOSTNAME$' \ '$HOSTOUTPUT$'
How do you see, these Commands when called (For an alert), will run our scripts, passing on Centreon's variables as arguments (The Host, The Service, Your Status…) and then OpenAi shakes, shake it and it will send us a message on Telegram something more interesting.
Remember to associate these Notification Commands with the appropriate users and reload the Centreon configuration, that never hurts 😉
Total, that after exporting we should start to receive somewhat different alerts, depending on what we have asked OpenIA! What do you think? Now it remains to continue squeezing it, Asking for solutions, speaking non-technical language… Or, modify the script and so that you receive alerts by Alexa, phone call with VoIP, mail, Teams, Slack, Discord…
As always wishing you find it interesting, something to give our monitoring system a little more spin! and for the skeptics who tell me that we are giving information to OpenAI, it does so equally by using external means of communication =) Nothing more than a hug, May it go very well, to be happy and above all to enjoy the summer that flies by!