SKUndef / octo-zab

Backend/Frontend application to remotely control multiple Zabbix servers (www.zabbix.com).
GNU General Public License v2.0
15 stars 7 forks source link

{HOSTNAME} not expanded on issues #5

Open jlauro opened 8 years ago

jlauro commented 8 years ago

Macros are not expanded on trigger items. Most noticeable is {HOSTNAME} as that is fairly common, but I think Zabbix supports a few others.

parisprobr commented 8 years ago

I think I found the solution:

Edit the /var/www/html/octozab/backend/server.js

the correct code for the function "getServerIssues" :


function getServerIssues(req, token, server) {
        req({
                body: {
                        method: 'trigger.get', jsonrpc: '2.0', id: 1, auth: token,
                        params: {
                                output:                         'extend',
                                monitored:                      true,
                                maintenance:            false,
                                min_severity:           2,
                                expandData:             'true',
                                selectLastEvent:        [ 'eventid', 'acknowledged' ],
                                filter:                         { value: 1 },
                                selectHosts:           'extend'
                        }
                }
        },
                function(err,resp,body) {
                        console.log(body);
                        if ((err === null) && (body.result !== undefined)) {

                                var severityMapping = {
                                                0: 'Not Classified',
                                                1: 'Information',
                                                2: 'Warning',
                                                3: 'Average',
                                                4: 'High',
                                                5: 'Disaster'
                                        },
                                        severityCount   = {},
                                        mapData                 = [];

                                body.result.forEach(function(issue) {
                                        issue.server                                    = server;
                                        issue.hostname                                  = issue.hosts[0].host;
                                        issue.hostid                                    = issue.hosts[0].hostid;
                                        severityCount[issue.priority]   = (severityCount[issue.priority]) ? severityCount[issue.priority] + 1 : 1;
                                });

                                mapData.push({
                                        id:             server,
                                        name:           server.toUpperCase(),
                                        colorValue: _.max(_.keys(severityCount))
                                });
                                console.log(server);

                                _.each(severityCount, function(v,k) {
                                        mapData.push({
                                                id:             server + '_' + k,
                                                name:           severityMapping[k],
                                                parent:         server,
                                                value:          v,
                                                colorValue: k
                                        });
                                });

                                pub.mset(
                                        'octo-zab:' + server + ':monitored:trigger.get.issues'          , JSON.stringify(body.result),
                                        'octo-zab:' + server + ':monitored:trigger.get.issues.map'      , JSON.stringify(mapData),
                                function(err) {
                                        if (err !== null) {
                                                log('err', 'mset', 'octo-zab:' + server + ':monitored:trigger.get.issues*');
                                        }
                                });
                        } else { log('err', 'request', server + ': trigger.get'); }
                }
        );

        getIssuesTasks[server] = setTimeout(function() { getServerIssues(req, token, server); }, 180000);
}