⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mtetrigger.c

📁 开发snmp的开发包有两个开放的SNMP开发库
💻 C
📖 第 1 页 / 共 4 页
字号:
        ((entry->mteTThRiseEvent[0] != '\0' ) ||         (entry->mteTThFallEvent[0] != '\0' ))) {        /*         * The same delta-sample validation from Boolean         *   tests also applies here too.         */        if (entry->flags & MTE_TRIGGER_FLAG_DELTA) {            vp2 = entry->old_results;            if (entry->flags & MTE_TRIGGER_FLAG_DWILD) {                dv1 = dvar;                dv2 = entry->old_deltaDs;            }        }        for ( vp1 = var; vp1; vp1=vp1->next_variable ) {            /*             * Determine the value to be monitored...             */            if ( !vp1->val.integer ) {  /* No value */                if ( vp2 )                    vp2 = vp2->next_variable;                continue;            }            if (entry->flags & MTE_TRIGGER_FLAG_DELTA) {                if (entry->flags & MTE_TRIGGER_FLAG_DWILD) {                    /*                     * We've already checked any non-wildcarded                     *   discontinuity markers (inc. sysUpTime.0).                     * Validate this particular sample against                     *   the relevant wildcarded marker...                     */                    if ((dv1->type == ASN_NULL)  ||                        (dv1->type != dv2->type) ||                        (*dv1->val.integer != *dv2->val.integer)) {                        /*                         * Bogus or changed discontinuity marker.                         * Need to skip this sample.                         */                        vp2 = vp2->next_variable;                        continue;                    }                }                /*                 * ... and check there is a previous sample to calculate                 *   the delta value against (regardless of whether the                 *   discontinuity marker was wildcarded or not).                 */                if (vp2->type == ASN_NULL) {                    vp2 = vp2->next_variable;                    continue;                }                value = (*vp1->val.integer - *vp2->val.integer);                vp2 = vp2->next_variable;            } else {                value = *vp1->val.integer;            }            /*             * ... evaluate the single-value comparisons,             *     and decide whether to trigger the event.             */            cmp = vp1->index;   /* working copy of 'armed' flags */            if ( value >= entry->mteTThRiseValue ) {                if ((entry->old_results ||                     (entry->mteTThStartup & MTE_THRESH_START_RISE)) &&                    (vp1->index & MTE_ARMED_TH_RISE )) {                    DEBUGMSGTL(( "disman:event:trigger:fire",                                 "Firing rising threshold test: "));                    DEBUGMSGOID(("disman:event:trigger:fire",                                 vp1->name, vp1->name_length));                    DEBUGMSG((   "disman:event:trigger:fire", "%s\n",                                 (entry->old_results ? "" : " (startup)")));                    cmp &= ~MTE_ARMED_TH_RISE;                    cmp |=  MTE_ARMED_TH_FALL;                    /*                     * If no riseEvent is configured, we need still to                     *  set the armed flags appropriately, but there's                     *  no point in trying to fire the (missing) event.                     */                    if (entry->mteTThRiseEvent[0] != '\0' ) {                        entry->mteTriggerXOwner   = entry->mteTThObjOwner;                        entry->mteTriggerXObjects = entry->mteTThObjects;                        entry->mteTriggerFired    = vp1;                        n = entry->mteTriggerValueID_len;                        mteEvent_fire(entry->mteTThRiseOwner,                                      entry->mteTThRiseEvent,                                       entry, vp1->name+n, vp1->name_length-n);                    }                }            }            if ( value <= entry->mteTThFallValue ) {                if ((entry->old_results ||                     (entry->mteTThStartup & MTE_THRESH_START_FALL)) &&                    (vp1->index & MTE_ARMED_TH_FALL )) {                    DEBUGMSGTL(( "disman:event:trigger:fire",                                 "Firing falling threshold test: "));                    DEBUGMSGOID(("disman:event:trigger:fire",                                 vp1->name, vp1->name_length));                    DEBUGMSG((   "disman:event:trigger:fire", "%s\n",                                 (entry->old_results ? "" : " (startup)")));                    cmp &= ~MTE_ARMED_TH_FALL;                    cmp |=  MTE_ARMED_TH_RISE;                    /*                     * Similarly, if no fallEvent is configured,                     *  there's no point in trying to fire it either.                     */                    if (entry->mteTThRiseEvent[0] != '\0' ) {                        entry->mteTriggerXOwner   = entry->mteTThObjOwner;                        entry->mteTriggerXObjects = entry->mteTThObjects;                        entry->mteTriggerFired    = vp1;                        n = entry->mteTriggerValueID_len;                        mteEvent_fire(entry->mteTThFallOwner,                                      entry->mteTThFallEvent,                                       entry, vp1->name+n, vp1->name_length-n);                    }                }            }            vp1->index = cmp;        }    }    /*     * The same processing also works for delta-threshold tests (if configured)     */    if (( entry->mteTriggerTest & MTE_TRIGGER_THRESHOLD ) &&        ((entry->mteTThDRiseEvent[0] != '\0' ) ||         (entry->mteTThDFallEvent[0] != '\0' ))) {        /*         * Delta-threshold tests can only be used with         *   absolute valued samples.         */        vp2 = entry->old_results;        if (entry->flags & MTE_TRIGGER_FLAG_DELTA) {            DEBUGMSGTL(( "disman:event:trigger",                         "Delta-threshold on delta-sample\n"));        } else if ( vp2 != NULL ) {          for ( vp1 = var; vp1; vp1=vp1->next_variable ) {            /*             * Determine the value to be monitored...             *  (similar to previous delta-sample processing,             *   but without the discontinuity marker checks)             */            if (!vp2) {                break;   /* Run out of 'old' values */            }            if (( !vp1->val.integer ) ||                (vp2->type == ASN_NULL)) {                vp2 = vp2->next_variable;                continue;            }            value = (*vp1->val.integer - *vp2->val.integer);            vp2 = vp2->next_variable;            /*             * ... evaluate the single-value comparisons,             *     and decide whether to trigger the event.             */            cmp = vp1->index;   /* working copy of 'armed' flags */            if ( value >= entry->mteTThDRiseValue ) {                if (vp1->index & MTE_ARMED_TH_DRISE ) {                    DEBUGMSGTL(( "disman:event:trigger:fire",                                 "Firing rising delta threshold test: "));                    DEBUGMSGOID(("disman:event:trigger:fire",                                 vp1->name, vp1->name_length));                    DEBUGMSG((   "disman:event:trigger:fire", "\n"));                    cmp &= ~MTE_ARMED_TH_DRISE;                    cmp |=  MTE_ARMED_TH_DFALL;                    /*                     * If no riseEvent is configured, we need still to                     *  set the armed flags appropriately, but there's                     *  no point in trying to fire the (missing) event.                     */                    if (entry->mteTThDRiseEvent[0] != '\0' ) {                        entry->mteTriggerXOwner   = entry->mteTThObjOwner;                        entry->mteTriggerXObjects = entry->mteTThObjects;                        entry->mteTriggerFired    = vp1;                        n = entry->mteTriggerValueID_len;                        mteEvent_fire(entry->mteTThDRiseOwner,                                      entry->mteTThDRiseEvent,                                       entry, vp1->name+n, vp1->name_length-n);                    }                }            }            if ( value <= entry->mteTThDFallValue ) {                if (vp1->index & MTE_ARMED_TH_DFALL ) {                    DEBUGMSGTL(( "disman:event:trigger:fire",                                 "Firing falling delta threshold test: "));                    DEBUGMSGOID(("disman:event:trigger:fire",                                 vp1->name, vp1->name_length));                    DEBUGMSG((   "disman:event:trigger:fire", "\n"));                    cmp &= ~MTE_ARMED_TH_DFALL;                    cmp |=  MTE_ARMED_TH_DRISE;                    /*                     * Similarly, if no fallEvent is configured,                     *  there's no point in trying to fire it either.                     */                    if (entry->mteTThDRiseEvent[0] != '\0' ) {                        entry->mteTriggerXOwner   = entry->mteTThObjOwner;                        entry->mteTriggerXObjects = entry->mteTThObjects;                        entry->mteTriggerFired    = vp1;                        n = entry->mteTriggerValueID_len;                        mteEvent_fire(entry->mteTThDFallOwner,                                      entry->mteTThDFallEvent,                                       entry, vp1->name+n, vp1->name_length-n);                    }                }            }            vp1->index = cmp;          }        }    }    /*     * Finally, rotate the results - ready for the next run.     */    snmp_free_varbind( entry->old_results );    entry->old_results = var;    if ( entry->flags & MTE_TRIGGER_FLAG_DELTA ) {        snmp_free_varbind( entry->old_deltaDs );        entry->old_deltaDs = dvar;        entry->sysUpTime   = *sysUT_var.val.integer;    }}voidmteTrigger_enable( struct mteTrigger *entry ){    if (!entry)        return;    if (entry->alarm) {        /* XXX - or explicitly call mteTrigger_disable ?? */        snmp_alarm_unregister( entry->alarm );        entry->alarm = 0;    }    if (entry->mteTriggerFrequency) {        /*         * register once to run ASAP, and another to run         * at the trigger frequency         */        snmp_alarm_register(0, 0, mteTrigger_run, entry );        entry->alarm = snmp_alarm_register(                           entry->mteTriggerFrequency, SA_REPEAT,                           mteTrigger_run, entry );    }}voidmteTrigger_disable( struct mteTrigger *entry ){    if (!entry)        return;    if (entry->alarm) {        snmp_alarm_unregister( entry->alarm );        entry->alarm = 0;        /* XXX - perhaps release any previous results */    }}long _mteTrigger_MaxCount = 0;long _mteTrigger_countEntries(void){    struct mteTrigger *entry;    netsnmp_tdata_row *row;    long count = 0;    for (row = netsnmp_tdata_row_first(trigger_table_data);         row;         row = netsnmp_tdata_row_next(trigger_table_data, row)) {        entry  = (struct mteTrigger *)row->data;        count += entry->count;    }    return count;}long mteTrigger_getNumEntries(int max){    long count;    /* XXX - implement some form of caching ??? */    count = _mteTrigger_countEntries();    if ( count > _mteTrigger_MaxCount )        _mteTrigger_MaxCount = count;        return ( max ?  _mteTrigger_MaxCount : count);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -