Skip to main content

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:

AD_4nXdd6OMtcfQfl3y2_vETDXkR6oU2k4kqeWii9BHHvioleS__8TwGDTrNA8MuUp2O4S7ZA0jgnBABlkZ9C1Qdauqs4mvpOdzrD953UdfWlf9AlkEbXy_VI_5-6NmR5xZloIJjKzm_cQ?key=7hUvHn8V2oQa-7dv2rXL81Or

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:

AD_4nXfsZfLWkUnAKD7TUwpg3IwA5d1qy1R1fl_2VRD_4VTSv-3yGfNeCY7I93Gz1rTJvi0F9JzxSgfcH5vswKzV5llsM8sCSqXReQf3OTTg8P4tPRokdVnMuhyD5X14BunUPv-kzxXGhg?key=7hUvHn8V2oQa-7dv2rXL81Or

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:

AD_4nXfpDHp2DFzzjvu7pqNYcTw0NUtsONv0uyt9o5xBvWcFk92X6pxjBfEWYZHAcS8YTwjPQvs_SeTsu5th0K7WK0pJsA161JO_sQDLKPnaIHyTxWSNLxqQbaRdsu_oEvupRyCQr6BJwQ?key=7hUvHn8V2oQa-7dv2rXL81Or

  • 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:

AD_4nXc9WULd9bdMYmeOhu4yxqyAzfmEYhUY9bLGvbxa-mGfH0DAdt8TYCOKcE3h_yeOQ_qRW4kDqrpslw4Rj0lgOcovyJgzjK_JLVWGS7bsJRXt8pNDHKrNatQxr9oQzSzfLhePvesT?key=7hUvHn8V2oQa-7dv2rXL81Or

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

AD_4nXd_-_2vaxNfFAtZ2owsFLl5jp04sEP5pT8AyqXy1Fge-vt9aE8jH_fJS1zFMcWhyKMRRvv1pjsTovR3FzI7eo8cLiC9ruyk1EK7PHb2MsIJcx5FyN6OQ-7DghISxgJJrtTD-PMU5A?key=7hUvHn8V2oQa-7dv2rXL81Or

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:

AD_4nXdzW4g1a4lQhCV3lR6uGsa7XsLTDaZpiIB-2uKmwOiDsVT_lk3mjap8nytJQUQajsMvoE3oxPrfnFSwkkINlA63H9b_Hm5wZYZIl0xGxfB1mlb8vWgr1qnPY9de8az63YPxb355Qg?key=7hUvHn8V2oQa-7dv2rXL81Or

And if we want information about the sql logger, we can just enter:

ccc -p51001 'GetLogInfo{str_arg:"sql"}'

AD_4nXex2F3fs6lJczrMSYVFONzcT5V-JWkWrbd-VDswB4jP8cfKGf8yzx9WmHA0o-GkEcqTURmcg8VNdSrV0XX_c6JPAwYvFOTjelhOqJdCnxtub4PAzaeCOOAc3aakCRmMcigDxnKELA?key=7hUvHn8V2oQa-7dv2rXL81Or

 

Setting a log level

 

Now, let’s take a look at the second function, SetLogLevel.

ccc -p51001 --help SetLogLevel

AD_4nXf5DxRxTT04Hv4K37tEHC1Q9kR2kJjY1wPC_kNhRhtP6MUkWOrHn02iHvMjptVVBRBueCoDDLhOXZkO2QkiCOI9fBCz8Cm_gWwpKaTkv8_0Bf_XCZem1mYYuBoUVGSFAZs8kkBewA?key=7hUvHn8V2oQa-7dv2rXL81Or

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"}'

AD_4nXfvCCtwHy9lx3cVhyi21hxZG1Z8-ah5QKMC9nJ5fJbOqvBXEw0seltm-qy04CH_J-u3pM3XBbuNQHqMN-FKg6SwzuP0gIiBaQ-pePdCuV14Mw0nbprwC9J_QLOkIsEwbwghONcz?key=7hUvHn8V2oQa-7dv2rXL81Or


We can then check the level is the correct one:

​​​​​​​ccc -p51001 'GetLogInfo{str_arg:"sql"}'

AD_4nXda6lEZ9-CUB9oMcejn041ZRr0QSGAFwPEtH0jjqdmGyuKT52CQjS3FGeez0peIusOduK6PTRu1PKYle8yKb3zRkyiIETpzjLT8XHVJyoKrWO11It6XhaZY9dg4XJkbASJRQ-Lc?key=7hUvHn8V2oQa-7dv2rXL81Or

 

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.

 

Be the first to reply!

Reply