Commit 32334cdc authored by Jan Koester's avatar Jan Koester
Browse files

test

parent 7d74277f
Loading
Loading
Loading
Loading
+30 −9
Changes for tools/mkzabbix.py: 30 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -168,6 +168,25 @@ if (d.trap === %d) {
return SKIP;''' % (t, t, t, c, 'status' if kind else '', c, event))


def status_text_script(t, sc, nc, kind):
    # "critical: 1 member(s) missing": status and why in one value, so a
    # trigger on it has both at once (two items of one notification are
    # processed in no particular order)
    return js('''
var NAME = '{#NAME}', WORD = {'1': 'ok', '2': 'warning', '3': 'critical', '4': 'unknown'};
function say(st, why) { st = status(st); return (WORD[st] || st) + (why ? ': ' + why : ''); }
if (d.trap === %d) {
  var all = rows(d, %d);
  for (var i = 0; i < all.length; i++)
    if (rowName(%d, all[i]) === NAME && all[i][%d] !== undefined) return say(all[i][%d], all[i][%d]);
}
if (d.trap === 10 || d.trap === 12 || d.trap === 13) {
  var ev = (d.rows[7] || {})[0];
  if (ev && ev[1] === '%s' && ev[2] === NAME) return say(ev[3], ev[5]);
}
return SKIP;''' % (t, t, t, sc, sc, nc, kind))


def discovery_script(t):
    extra = ''
    if t == 8:
@@ -260,12 +279,14 @@ def discovery(prefix):
    base = 'snmpdd.%s' % prefix
    tags = (('component', kind),)
    status_key = '%s.status["{#NAME}"]' % base
    note_key = '%s.note["{#NAME}"]' % base
    text_key = '%s.statustext["{#NAME}"]' % base
    items = [
        dependent('%s: status' % label, status_key, column_script(num, col(prefix, 'Status'), kind),
                  valuemap='snmpdd status', tags=tags, uuid_parts=('proto', status_key)),
        dependent('%s: note' % label, note_key, column_script(num, col(prefix, 'Note')), value_type='TEXT',
                  tags=tags, history='30d', uuid_parts=('proto', note_key)),
        dependent('%s: status text' % label, text_key,
                  status_text_script(num, col(prefix, 'Status'), col(prefix, 'Note'), kind), value_type='TEXT',
                  tags=tags, history='30d', uuid_parts=('proto', text_key),
                  description='The status and why it isn\'t ok, e.g. "critical: 1 member(s) missing".'),
    ]
    for mib, name, vt, units in columns:
        key = '%s.%s["{#NAME}"]' % (base, mib.lower())
@@ -274,15 +295,15 @@ def discovery(prefix):
                               uuid_parts=('proto', key)))
    crit, warn = SEVERITY[prefix]
    triggers = []
    for value, sev, word in ((3, crit, 'critical'), (2, warn, 'warning')):
    for sev, word in ((crit, 'critical'), (warn, 'warning')):
        triggers.append({
            'uuid': uid('trigger', prefix, word),
            # the note only for the operational data (always there with the status)
            'expression': '%s=%d and length(%s)>=0' % (expr(status_key), value, expr(note_key)),
            'name': '%s: %s' % (label, word),
            'opdata': '{ITEM.LASTVALUE2}',
            'expression': 'find(/%s/%s,,"regexp","^%s")=1' % (TEMPLATE, text_key, word),
            # the name with the value it fired on: "RAID md0: critical: 1 member(s) missing"
            'name': '%s: {ITEM.VALUE1}' % label,
            'event_name': '%s: {ITEM.VALUE1}' % label,
            'priority': sev,
            'description': 'snmpdd reports the status %s; the note says why.' % word,
            'description': 'snmpdd reports the status %s; the text after it says why.' % word,
            'tags': [{'tag': 'scope', 'value': 'availability'}],
        })
    return {
+114 −78

File changed.

Preview size limit exceeded, changes collapsed.