Centreon alerts with Ollama local AI

Very good! The intention of this post is to make a mere example of how we can use AI in our monitoring environment, In this first document we will guide you to the reception of the alerts, in this case of Centreon. So if you're bored of traditional notifications, AI has come to change it!

What I said, In this first post we will see how to use the Ollama's AI so that it transfers the notifications from our monitoring system to us in a friendlier way, More human… If we want, we can tell her to give us recommendations or advice to act, or that he does it in verse… The idea is that Centreon will send it via API to Ollama every time a Host or a Service has a problem, we will create a couple of very simple scripts that we will use so that the alert is sent to Ollama, with a text where we will detail what we want from it and we will pass as arguments the Host or Service that fails, as well as its…

We therefore began by creating those 2 Scripts, in my case I will use notifications with Telegram, So if you are going to use mail or another service you will have to do that part differently.

We create the script for the host notifications, We call it '/usr/lib/centreon/plugins/notifica_telegram_ia_ollama_host.sh’ For example. In it we will give you the appropriate indications that we consider, I leave you my example, you will have to take into account modifying the Ollama IP, as well as the Telegram group's Chat ID, the Telegram Token, the LLM language model used or for example the temperature to make it more or less creative. This would be the content:

#!/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 can be technical, Don't offer yourself as help, Don't give recommendations. The message you have to say is about a problem of type: "$1", In the team "$2" since it's in the state "$3". Don't say hello, Don't say hello and don't say goodbye, Don't even thank you for anything. The answer should be in Spanish and the message should be brief."

texto_generado=$(/usr/bin/curl http://DIRECCION_IP_OLLAMA:11434/api/generate -H "Content-Type: application/json" -d '{
  "model": "llama3",
  "prompt": "'"$text"'",
  "temperature": 0.1,
  "Stream": False,
  "max_length": 50
}' | jq -r '.response')

texto_generado_sin_comillas='echo "$texto_generado" | sed 's/\"//g'`

/usr/bin/curl -X POST -H "Content-Type: application/json" -d '{
  "chat_id": "-XXXXXXXXXX",
  "text": "'"$texto_generado_sin_comillas"'"
}' "https://api.telegram.org/botTOKEN_BOT_TELEGRAM/sendMessage"

E igualmente deberemos generar el script que usará Centreon para notificar cualquier problema en los Servicios, for this, We also created for example this script called '/usr/lib/centreon/plugins/notifica_telegram_ia_ollama_servicio.sh’ where if you look at it is very similar, but he has 1 Argument More.

#!/bin/bash text="Please, generates a text for a notification that will be sent to the user's smartphone. You're a personal agent who generates text for IT technicians. Your answers can be technical. 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". Don't say hello. Don't say goodbye. Don't say thank you. The answer must be in Spanish. The message should be brief, In one paragraph your answer"

texto_generado=$(/usr/bin/curl http://DIRECCION_IP_OLLAMA:11434/api/generate -H "Content-Type: application/json" -d '{
  "model": "llama3",
  "prompt": "'"$text"'",
  "temperature": 0.1,
  "Stream": False,
  "max_length": 50
}' | jq -r '.response')

texto_generado_sin_comillas='echo "$texto_generado" | sed 's/\"//g'`

/usr/bin/curl -X POST -H "Content-Type: application/json" -d '{
  "chat_id": "-ID_CHAT_TELEGRAM",
  "text": "'"$texto_generado_sin_comillas"'"
}' "https://api.telegram.org/botTOKEN_TELEGRAM/sendMessage"

After that, remember to make them executable (With Chmod +D) and the next thing would be to create the Notification Type Commands in Centreon, We're going to “Configuration” > “Commands” > “Notifications” and we created a couple of them, one to report problems with the Hosts and one for the Services, each with their own Command Line:

  • /usr/lib/centreon/plugins/notifica_telegram_ia_ollama_host.sh '$HOSTSTATE$’ \ '$HOSTNAME$’ \ '$HOSTOUTPUT$’
  • /usr/lib/centreon/plugins/notifica_telegram_ia_ollama_servicio.sh '$SERVICESTATE$’ \ '$HOSTNAME$’ \ '$SERVICEDESC$’ \ '$SERVICEOUTPUT$’

And once the Notification Commands have been created, they will be associated with a User or a Group, so select the user or group you have associated with your Hosts and Services and we indicate the newly created Commands in 'Host Notification Commands’ and on 'Service Notification Commands'.

We record and export, In case it is necessary, and that's it!

And nothing, Now every time you have an alert in your datacenter it will be different, as curious as vosotr@s want it to be, Short, Long, with resolution options, in Basque, In Swahili…

I hope you found it curious and nothing, As I said, as always everything goes great!

A hug!

Recommended Posts

Author

nheobug@bujarra.com
Autor del blog Bujarra.com Cualquier necesidad que tengas, Do not hesitate to contact me, I will try to help you whenever I can, Sharing is living ;) . Enjoy documents!!!