zabbix_sender over HTTP - how to send data to Zabbix over HTTP | S

In this article, I will provide a possible solution to the problem for many system administrators who use the Zabbix monitoring system . It is especially useful for those who monitor various programs in Zabbix: telephony systems, various routine operations with the database, 1C (yes, yes, we are such perverts people with non-standard thinking that we monitor 1C in Zabbix). I myself was tormented by making Powershell scripts, I use zabbix_sender.exe to send it. There were terrible times.

How did we get to this


I have been using this system for several years. In the beginning, they were used to monitor availability (yeah, icmp requests were done with such a combine and that's it). Now we use almost all the functionality, maps, inventory, reports. Recently, they began to tighten monitoring of backups (not only Linux systems, but also different Windows), monitoring various programs (cash programs in retail), exchanges, synchronization. And every time I had to write scripts, because many programs could not run zabbix_sender.exe with the necessary parameters themselves (especially for 1C). Other scripts were written to monitor these scripts. The program exports something to a file, the script parses it, sends everything through zabbix_sender.

Each time, as a system administrator, I had to make all the scripts. 1C programmers just wrote files, the logic was all on me. This, like any lazy system administrator, did not suit me .
I was always indignant (especially at the beginning) why there is no web interface for sending values ​​to Zabbix? And now everything is simpler - well, if not, then write it!

Implementation


Excuses, apologies
I must say right away that I'm not a PHP programmer, so for smart programmers, code can cause bleeding from the eye area. Also, this solution should not be subjected to heavy load, a separate instance of zabbix_sender is launched for each value, if you need to send many values ​​at once, it might be worth looking in the API and setting up one session, without breaking. In this way, we get about 200 parameters per minute, while the flight is excellent!

Let's get started! Create the zabbix_sender folder on the zabbix server (I have the / var / www / zabbix folder, do not forget about root rights):

mkdir /var/www/zabbix/zabbix_sender
chown www-data:www-data /var/www/zabbix/zabbix_sender

Create an index.php file, contents in
spoiler
";
        echo "server=$server, key=$key, value=$value";
        echo "
"; var_dump($out); echo "
"; var_dump($err); //Log error $ip_address=get_client_ip(); $error_msg= date('Y-m-d H:i:s') . " - ZABBIX_SENDER[error] - FROM: $ip_address; HTTP_PARAM: server=$server, key=$key, value=$value; ERROR: zabbix_sender: $out[0]\n"; error_log($error_msg,3,"/var/log/apache2/zabbix_sender.log"); }


To send a value. you just need to write in the browser (or in a program that can make an HTTP GET request) a request of the form zabbix.domain.com/zabbix_sender/index.php?server=myhost&key=testitem&value=11 . Where server is the host in the zabbix (case-sensitive name!), Key / value is the name and value of item.

More or for those interested


The get_client_ip function takes the IP address of the client that it sent (we will write to the log for debugging with errors).

Only two possible errors. Error when executing zabbix_sender, write to the log (which is located in /var/www/apache2/zabbix_sender.log )
ZABBIX_SENDER[error] - FROM: $ip_address; HTTP_PARAM: server=$server, key=$key, value=$value; ERROR: zabbix_sender

There is no get parameter
ZABBIX_SENDER[warning] - FROM: $ip_address; HTTP_PARAM: server=$server, key=$key, value=$value; ERROR: parametr KEY is EMPTY

Where $ ip_address - from which IP address the value was sent, I think the other parameters are clear.

We monitor the monitoring system


It’s bad to look at errors after the monitoring has not worked, so we will monitor the monitoring.
To do this, add to zabbix_agentd.conf:

UserParameter=zabbix_sender_web_status_error, grep -q 'ZABBIX_SENDER\[error\]' /var/log/apache2/zabbix_sender.log; echo $?;
UserParameter=zabbix_sender_web_status_warning, grep -q 'ZABBIX_SENDER\[warning\]' /var/log/apache2/zabbix_sender.log; echo $?;

Restart the agent. So that the logs are cleaned once a day (and the error hangs only one day), we check that there is a /etc/logrotate.d/apache2 file with the contents:

/var/log/apache2/*.log {
        daily
        missingok
        rotate 52
        compress
        delaycompress
        notifempty
        create 644 www-data www-data
        sharedscripts
        postrotate
                /etc/init.d/apache2 reload > /dev/null
        endscript
}

In the Zabbix Server host, add two items:

image
image

And two triggers:




In the end


In total, we got a new API for sending values ​​to Zabbix. Now we give the link to the programmers zabbix.domain.com/zabbix_sender/index.php?server=myhost&key=testitem&value=11 , create the necessary Templates, bind to the hosts ... Well, we do a lot more, but without zabbix_sender, but with a fashionable web API. Programmers themselves can track the success or failure of delivery, if everything is fine, then the web server will return the OK page, if not, it will tell which parameter is not. Well, if it's really hard, then Zabbix will say that it has an error.

PS I want to hear constructive criticism, maybe there are even similar solutions, but I did not find them.

Also popular now: