We connect a production calendar in Zabbix

As we all know, the work process of an enterprise, in accordance with official national and international holidays, often requires a change in the production process in terms of shifting or replacing working and non-working days. Many organizations have internal production calendars, on the schedule of which work technological and business processes. Monitoring systems that work autonomously, are often configured to monitor business processes as part of the normal activities of the enterprise and have a fixed fixed schedule for monitoring information flows and data accompanying business processes. At the time of changing the daily work schedule, administrators require manual actions to change the monitoring logic.How to get Zabbix to use a production calendar? Let's consider a few options in more detail.


Introduction


Everyone who worked with Zabbix knows that the logic of monitoring certain services is formed using templates that connect to servers with controlled services. Changing the logic of work or the schedule for checking services is a rather time-consuming task, which depends on the number of controlled elements. Changing the working schedule, when instead of the working day a holiday is declared, in order to avoid erroneous triggering of triggers for events, forces administrators to send the monitoring circuit to the Maintenance mode. In the case of a working day on the weekend, you have to include a lot of monitoring services with your hands to control the work of business processes.


The official recommendation for flexible scheduling of monitoring triggers from Zabbix is ​​to replace the parameters of the scan cycles with global macros
https://habr.com/en/company/zabbix/blog/344492/ .
But this solution does not allow to automate the
on / off process of checking services on a schedule in an explicit form.


Zabbix server is an autonomous system that clearly works within the framework of its internal logic. Therefore, external influences on the system are not recommended.


Let's try to implement the logic of the production calendar based on internal Zabbix mechanisms.


, . , .
github.com, .



Zabbix :


  • Zabbix
  • Zabbix
  • ()

Zabbix


Zabbix :


  • ,
  • ""


  • , /
  • ,
  • HTTP/HTTPS


:




  • Zabbix-agent. Zabbix-agent
  • , ,

β„–1


.
{$DATEURL} . "HTTP agent" "holiday.date.by.http".


( 1). 1. .



.
"Preprocessing" "$.date".



, "holiday.date.by.http" .


"Calculated" "today.is.a.holiday"



:
last(holiday.date.by.http)=date(system.localtime)
"Numeric(Unsigned)"


, 0 1.


, 0 1 . , "" , . .


, :


  • " "
  • " "

" "


" " . .


:


{Zabbix server:system.users.num.last()}>1


{Zabbix server:system.users.num.last()}>1 and {Zabbix server:today.is.a.holiday.last()}=0

.
.


" "


"/".


"today.is.a.holiday" .



.



.


. "{Zabbix server:system.users.num.last()}>1", 1.


"{Zabbix server:proc.num.last()}>20"


""





(, TG, SMS).


. . .


β„–2


, Zabbix . , . .
?


1


- , .


2


, .


, .
, . {$HOLIDAY_DATE}. , , Zabbix-agent, {$CURRENT_DATE} .


InfluxDB. , 1 5 .


InfluxDB


, . fuzzytime . .



                <item>
                    <name>Today is a holiday</name>
                    <type>CALCULATED</type>
                    <key>influxdb.holiday</key>
                    <history>1h</history>
                    <trends>0</trends>
                    <params>date(system.localtime)={$HOLIDAY_DATE}</params>
                    <applications>
                        <application>
                            <name>InfluxDB DataCheck</name>
                        </application>
                    </applications>
                    <triggers>
                        <trigger>
                            <expression>{last()}</expression>
                            <name>InfluxDB Holiday Activated</name>
                            <opdata>If Fired - all dependent triggers are disabled</opdata>
                            <priority>INFO</priority>
                            <description>       </description>
                        </trigger>
                    </triggers>
                </item>

.
, .


     <params>{$CURRENT_DATE}={$HOLIDAY_DATE}</params>

, .


"" , " , Zabbix ?"


, , . Zabbix JSON RPC, , . Zabbix , , . , Zabbix , .




Preprocessing .



Preprocessing Script
//Zabbix.Log(2, 'Date Update request value='+value);
var authtoken = '';
var globalmacroid = -1;

var req = new CurlHttpRequest();
req.AddHeader('Content-Type: application/json');
resp = req.Post("{$DATEURL}", '{}');
var holidaydate = JSON.parse(resp).date;

Zabbix.Log(2, 'Found new holiday date='+holidaydate);

resp = req.Post("{$JSONRPC}", '{"jsonrpc": "2.0","method": "user.login","params": {"user": "Calendar","password": "SomePassword"},"id": 1}');

//   

if (req.Status() == 200) {
    jv = JSON.parse(resp);
    if (jv.result)
       authtoken= jv.result;
    else
       return 0;
}
else
    return 0;

//    

var reqmacros = 
{
    "jsonrpc": "2.0",
    "method": "usermacro.get",
    "params": {
        "output": "extend",
        "globalmacro": true
    },
    "auth": authtoken,
    "id": 1
}

resp = req.Post("{$JSONRPC}", JSON.stringify(reqmacros));
if (req.Status() == 200) {
    var jv = JSON.parse(resp);
    for(item in jv.result) {
        if (jv.result[item].macro == '{\$HOLIDAY_DATE}')
            {
                globalmacroid = jv.result[item].globalmacroid
                Zabbix.Log(2, 'Old Date value: '+jv.result[item].value)
            }
        }
    if (globalmacroid == -1)
        return 0;
}
else
{
    return 0;
}

//      

var changemacros = 
{   "jsonrpc": "2.0",
    "method": "usermacro.updateglobal",
    "params": {
        "globalmacroid": globalmacroid,
        "value": holidaydate
    },
    "auth": authtoken,
    "id": 1
}

resp = req.Post("{$JSONRPC}", JSON.stringify(changemacros));

if (req.Status() == 200) {
   jv = JSON.parse(resp);
   if (jv.result.globalmacroids.indexOf(globalmacroid) != -1)
        return 1
}
return 0;

"{$HOLIDAY_DATE}" "{$CURRENT_DATE}". , . β€” . .


, , / , -, / .


P.S.: , WEB , "HTTP agent" .
github.com


UPD: .


" ". 4.X , . , .


Β© Aborche 2020
Aborche


All Articles