Introduction
Sometimes you have an issue with Engine or Broker and you would like to change a log level to understand the issue, for example change the sql log level to trace but without reloading/restarting Broker because otherwise you will lose the issue you encounter.
Thanks to the gRPC API provided by Engine and Broker, it is possible.
About the gRPC API
Nowadays, Broker and Engine have a gRPC API accessible directly from localhost. If you execute the following command on your central server:
ss -plant | grep cbd | grep LISTEN
… you will get something like this:
Each line represents a TCP server. Here we are interested in the ones with ports in the n51000, 51999] range. You can see four lines with ports 51001 or 51002 in the example.
These ports can be different on your platform, so make sure you test your configuration.
We have two instances of Broker, so 51001 is the port used by the first one and 51002 is the port used by the second one.
If we run a similar command for Engine:
ss -plant | grep centengine | grep LISTEN
… then we get something like:
This time we get two lines with the same port. The gRPC API for Engine is in the 50000, 50999] range, and in the example we can read 50618.
Communicating through the gRPC API
If you want to talk to Engine or Broker through their gRPC API, you have to install the ccc tool. Depending on your distribution, you can install it using:
apt-get install centreon-collect-client
or
dnf install centreon-collect-client
To check it is correctly installed, run the following command (51001 is the listening port for Broker or Engine):
ccc -p51001
The answer you receive should look like this:
- To get help on the program, use the following command:
ccc --help
-
To list the available commands:
ccc -p51001 --list
It is important to note that the answer is not the same when querying Broker or Engine.
Functions about logs
In the case of Broker, the answer contains these lines:
So we have two functions about logs:
- The first one to get info about loggers
- The second one to change a log level.
Let’s try the first one. We can start with:
ccc -p51001 --help GetLogInfo
So we know this function needs a string argument. We also know this string can be empty. Let’s try it:
ccc -p51001 'GetLogInfo{}'
Then we get some information about all the loggers:
And if we want information about the sql logger, we can just enter:
ccc -p51001 'GetLogInfo{str_arg:"sql"}'
Setting a log level
Now, let’s take a look at the second function, SetLogLevel.
ccc -p51001 --help SetLogLevel
Here the function needs two arguments: the logger name and the new level. Let’s try to change the sql level to debug:
ccc -p51001 'SetLogLevel{logger:"sql", level:"ERROR"}'
We can then check the level is the correct one:
ccc -p51001 'GetLogInfo{str_arg:"sql"}'
Conclusion
As you can see, we were able to change the log level of the sql logger without reloading or restarting Broker. Bear in mind that this change is temporary: the next time Broker or Engine is restarted (e.g. when you deploy the configuration), the log level will revert to the value defined in the interface.