Zabbix + Communigate Pro: low-level discovery and account monitoring


    In my first publication, I talked about how you can configure the monitoring of queues of Communigate Pro (CGP) mail servers in Zabbix. Today I will tell about my little experience in using low-level discover (LLD) Zabbix to monitor the number of users in domains. I must say right away that in my opinion, the practical sense is precisely from monitoring the number of users. This was done more for my own joy and the ability to quickly answer the bosses the question “how many users do we have?” Without having to run through all the servers.

    Low-level discover

    LLD provides the ability to automatically create data elements, triggers, and graphs for various computer settings. For example, Zabbix can automatically collect data about your file system or network interfaces and build data items for monitoring based on this information.
    In order for LLD to be possible, we need to add a user parameter to the Zabbix agent settings, the request of which will return a list of JSON objects to the monitoring server, each of which, for example, for network interfaces, corresponds to one interface.


    It is necessary to make it possible to "monitor" the number of users on all domains of the CGP server + the total number of users on the server.
    The implementation of this task consists of the following steps:
    1. A script to get a list of CGP domains for LLD.
    2. A script to get the number of accounts for a domain.
    3. Place these scripts on the server.
    4. Configure Zabbix agent.
    5. Create a template in Zabbix to monitor the number of accounts.
    6. Add this template to the desired nodes in Zabbix.

    Important notice! The scripts that are used in this case require the user whose name they use in their work to have the “Can Modify All Domains and Accounts Settings” access right (see more details here) These are very serious rights that allow you to simply clear the domain of users. Accordingly, all that you do - you do at your own peril and risk.

    1. Script to get the list of CGP domains for LLD

    Both scripts use in their work barley library , which allows access to the API the Communigate Pro.
    For the first script, we need one simple ListDomains function, which returns a list of server domains.
    An important feature of this script is the need to return a response in JSON format. I did not want to put a separate JSON library for the pearl (JSON :: DWIW, for example), so as not to produce additional dependencies. I decided that in this case, Perl tools can be completely dispensed with.
    The main features of the script are presented in its help:

    discovery_cgp_domains [-h hostname] [-p port] -u username -w password
    discovery_cgp_domains -h|--help
    	-h hostname - address of DNS name of the server (Default: localhost)
    	-p port - port for connection (Default: 106)
    	-u username - account on CGatePro with grant 'Can Modify All Domains and Accounts Settings'
    	-w password - user password
    	--help - print this help
    	--debug - show debug lines

    The source code of the script can be seen here .
    Usage example:
    torwald@torwald-station:~/cgp_utility$ ./ -h -u cgpmonitor -w password

    As we can see, the answer contains a list of objects with one attribute - "#CGPDOMAIN", each of which represents one domain on the server. The attribute name will be used later in LLD configuration.

    2. A script to get the number of accounts for a domain.

    In the second script, add another function - ListAccounts (domain). As the name implies, it returns a list of domain users. There is no separate function for getting the number of users in the CGP API, so I just use the calculation of the length of the list of users.
    In addition, the script can summarize the number of all users on the server. To do this, it must be called with the -d TOTAL option.
    All script options are also presented in its help:
    count_cgp_account [-h hostname] [-p port] -u username -w password [-d domain]
    count_cgp_account -h|--help
    	-h hostname - address of DNS name of the server (Default: localhost)
    	-p port - port for connection (Default: 106)
    	-u username - account on CGatePro with grant 'Can Modify All Domains and Accounts Settings'
    	-w password - user password
    	-d domain - domain name to count accounts; if you use -d TOTAL then you'll get number of all accounts on server
    	--help - print this help
    	--debug - show debug lines

    The script simply displays the number of users on the server. Work example:
    # количество пользователей домена
    torwald@torwald-station:~/cgp_utility$ ./ -h -u cgpmonitor -w password -d
    # общее число пользователей
    torwald@torwald-station:~/cgp_utility$ ./ -h -u cgpmonitor -w password -d TOTAL
    # общее число пользователей - более простой вариант
    torwald@torwald-station:~/cgp_utility$ ./ -h -u cgpmonitor -w password

    The source code lies here .

    3. We place scripts on the server

    In this case, everything is quite simple:
    1. We place the utility in / usr / local / bin (you can "cut off" the extension) and give the user the rights to the zabbix agent (by default - zabbix) to run this utility.
    2. We place the module where it will be "visible" to the Perl interpreter, launched on behalf of zabbix. I have this / usr / local / lib / perl5.
    3. In the CGP admin interface, create a user (for example, cgpmon) with the rights “Can Modify All Domains and Accounts Settings”.
    4. We check the connection from under the zabbix user.

    4. Configure Zabbix Agent

    1. Add the following settings to the agent configuration file.

    # /etc/zabbix_agentd.conf
    # low-level discovery доменов Communigate,/usr/local/bin/discovery_cgp_domains -u cgpmon -w password
    # количество пользователей домена
    UserParameter=cgp.domain.accounts.count[*],/usr/local/bin/check_cgp_queue -u cgpmon -w password -d $1

    More information about the syntax of working with this parameter and the "asterisk", in particular, can be found in the documentation .
    Thus, now we can use the monitoring agent to get a list of domains and the number of accounts in this domain.

    2. Restart the agent so that the new settings take effect.

    5. Configuring the Zabbix template

    To work with account monitoring, I created a separate template - Template Communigate Domains Info.

    Item group

    First of all, you should create a group of data elements in the template. In my case, this is CGP.DomainsInfo. This will allow all data elements generated after LLD to be collected in one place.

    Discovery rule

    Open the template and go to the Discovery Rules, where we create a new rule:

    Pay attention to the Macro field. In it we write the attribute name "{#CGPDOMAIN}". As we recall, it is contained in all objects returned by the script to obtain a list of domains. And it is precisely the value of this attribute that all our prototypes (data, triggers and graphs) will use. Often, performing LLD for servers is not worth it, once a day is enough. In my case, that’s how they could be delivered at least once a month.

    Data Item Prototype

    After these preparations, go to the Prototypes of data elements and create a new prototype:

    Here, you should also pay attention to the use of the string "{#CGPDOMAIN}" in the Name and Key fields. When generating new data items, this string will be replaced with the corresponding domain name. Also, do not forget to specify the created Group of elements, otherwise we risk getting a large list of "homeless" data elements.

    If desired, prototype triggers can be prescribed. For example, the trigger for creating and deleting accounts.

    Rule for the total number of users

    After creating all the prototypes, add a rule to the template to monitor the total number of accounts on the server:

    Hurry Template

    For hurrying ready-made template can be taken here .

    6. Add nodes to the template

    Nothing complicated or RTFM here. After adding, we wait for LLD to work, and we get monitoring of the number of users.


    Why this monitoring is needed, I, as I said, do not know. For now. I hope that smart people will tell me what you can do with this data.
    In addition, such an implementation, in principle, is not safe, because we must keep the password for the Communigate account with good rights in the config. But this, in principle, can be circumvented.
    Also, almost the same information can be obtained using OS commands.
    For example, you can get a list of domains simply by scanning the Domains directory in the Communigate directory.
    And the number of users is to recursively calculate the number of directories of the form username.macnt inside the domain.
    But in this case, I wanted to show a general principle of how to automatically collect any information with Communigate using Zabbix. And how to get the necessary data in different ways.

    Only registered users can participate in the survey. Please come in.

    Do you need to monitor the number of accounts on the mail server

    • 54.7% Yes, I need 23
    • 21.4% No, not needed 9
    • 23.8% Needed in individual cases (which - I will indicate in the comments) 10

    Also popular now: