static inline void pike_raise_event(char *ip) { evi_params_p list; str ip_str; static str parameter_str = { "ip", 2 }; if (pike_event_id == EVI_ERROR) { LM_ERR("event not registered %d\n", pike_event_id); return; } if (evi_probe_event(pike_event_id)) { if (!(list = evi_get_params())) return; ip_str.s = ip; ip_str.len = strlen(ip); if (evi_param_add_str(list, ¶meter_str, &ip_str)) { LM_ERR("unable to add socket parameter\n"); evi_free_params(list); return; } if (evi_raise_event(pike_event_id, list)) { LM_ERR("unable to send event %d\n", pike_event_id); } } else { LM_DBG("no event sent\n"); } }
void shm_event_raise(long used, long size, long perc) { evi_params_p list = 0; *event_shm_pending = 1; *event_shm_last = perc; // event has to be triggered - check for subscribers if (!evi_probe_event(EVI_SHM_THRESHOLD_ID)) { goto end; } if (!(list = evi_get_params())) goto end; if (evi_param_add_int(list, &shm_usage_str, (int *)&perc)) { LM_ERR("unable to add usage parameter\n"); goto end; } if (evi_param_add_int(list, &shm_threshold_str, (int *)&event_shm_threshold)) { LM_ERR("unable to add threshold parameter\n"); goto end; } if (evi_param_add_int(list, &shm_used_str, (int *)&used)) { LM_ERR("unable to add used parameter\n"); goto end; } if (evi_param_add_int(list, &shm_size_str, (int *)&size)) { LM_ERR("unable to add size parameter\n"); goto end; } /* * event has to be raised without the lock otherwise a deadlock will be * generated by the transport modules, or by the event_route processing */ #ifdef HP_MALLOC shm_unlock(0); #else shm_unlock(); #endif if (evi_raise_event(EVI_SHM_THRESHOLD_ID, list)) { LM_ERR("unable to send shm threshold event\n"); } #ifdef HP_MALLOC shm_lock(0); #else shm_lock(); #endif list = 0; end: if (list) evi_free_params(list); *event_shm_pending = 0; }
void pkg_event_raise(long used, long size, long perc) { evi_params_p list = 0; int pid; event_pkg_pending = 1; event_pkg_last = perc; // event has to be triggered - check for subscribers if (!evi_probe_event(EVI_PKG_THRESHOLD_ID)) { goto end; } if (!(list = evi_get_params())) goto end; if (evi_param_add_int(list, &pkg_usage_str, (int *)&perc)) { LM_ERR("unable to add usage parameter\n"); goto end; } if (evi_param_add_int(list, &pkg_threshold_str, (int *)&event_pkg_threshold)) { LM_ERR("unable to add threshold parameter\n"); goto end; } if (evi_param_add_int(list, &pkg_used_str, (int *)&used)) { LM_ERR("unable to add used parameter\n"); goto end; } if (evi_param_add_int(list, &pkg_size_str, (int *)&size)) { LM_ERR("unable to add size parameter\n"); goto end; } pid = getpid(); if (evi_param_add_int(list, &pkg_pid_str, (int *)&pid)) { LM_ERR("unable to add size parameter\n"); goto end; } if (evi_raise_event(EVI_PKG_THRESHOLD_ID, list)) { LM_ERR("unable to send pkg threshold event\n"); } list = 0; end: if (list) evi_free_params(list); event_pkg_pending = 0; }
static inline void mysql_raise_event(const db_con_t *conn) { evi_params_p list = NULL; if (mysql_evi_id == EVI_ERROR) { LM_ERR("event not registered %d\n", mysql_evi_id); return; } if (!conn) { LM_ERR("no connection specified\n"); return; } if (mysql_last_event == CON_DISCON(conn)) { LM_DBG("MySQL status has not changed: %s\n", mysql_last_event ? "disconnected" : "connected"); return; } mysql_last_event = CON_DISCON(conn); if (evi_probe_event(mysql_evi_id)) { if (!(list = evi_get_params())) return; if (evi_param_add_str(list, &mysql_url_str, (void*)&conn->url)) { LM_ERR("unable to add url parameter\n"); goto free; } if (evi_param_add_str(list, &mysql_stat_str, CON_DISCON(conn) ? &mysql_stat_disconnected_str : &mysql_stat_connected_str)) { LM_ERR("unable to add status parameter\n"); goto free; } if (evi_raise_event(mysql_evi_id, list)) { LM_ERR("unable to send event\n"); } } else { LM_DBG("no event sent\n"); } return; free: evi_free_params(list); }
void lb_raise_event(struct lb_dst *dst) { evi_params_p list = NULL; if (lb_evi_id == EVI_ERROR || !evi_probe_event(lb_evi_id)) return; list = evi_get_params(); if (!list) { LM_ERR("cannot create event params\n"); return; } if (evi_param_add_int(list, &lb_group_str, &dst->group) < 0) { LM_ERR("cannot add destination group\n"); goto error; } if (evi_param_add_str(list, &lb_uri_str, &dst->uri) < 0) { LM_ERR("cannot add destination uri\n"); goto error; } if (evi_param_add_str(list, &lb_state_str, dst->flags&LB_DST_STAT_DSBL_FLAG ? &lb_disabled_str : &lb_enabled_str) < 0) { LM_ERR("cannot add destination state\n"); goto error; } if (evi_raise_event(lb_evi_id, list)) { LM_ERR("unable to send %.*s event\n", lb_event.len, lb_event.s); } return; error: evi_free_params(list); }
int evi_raise_script_event(event_id_t id, void * _a, void * _v) { pv_spec_p vals = (pv_spec_p)_v; pv_spec_p attrs = (pv_spec_p)_a; struct usr_avp *v_avp = NULL; struct usr_avp *a_avp = NULL; int err = evi_probe_event(id); int_str val, attr; str *at; evi_params_p params = NULL; if (err < 0) return err; else if (!err) return 1; if (!vals) goto raise; if (!(params = evi_get_params())) { LM_ERR("cannot create parameters list\n"); goto raise; } /* handle parameters */ while ((v_avp = search_first_avp(vals->pvp.pvn.u.isname.type, vals->pvp.pvn.u.isname.name.n, &val, v_avp))) { at = NULL; /* check attribute */ if (attrs) { err = -1; a_avp = search_first_avp(attrs->pvp.pvn.u.isname.type, attrs->pvp.pvn.u.isname.name.n, &attr, a_avp); if (!a_avp) { LM_ERR("missing attribute\n"); goto error; } if (!(a_avp->flags & AVP_VAL_STR)) { LM_ERR("invalid attribute name - must be string\n"); goto error; } at = &attr.s; } if (v_avp->flags & AVP_VAL_STR) err = evi_param_add_str(params, at, &val.s); else err = evi_param_add_int(params, at, &val.n); if (err) { LM_ERR("error while adding parameter\n"); goto error; } } /* check if there were too many attribute names */ if (attrs && a_avp && search_first_avp(attrs->pvp.pvn.u.isname.type, attrs->pvp.pvn.u.isname.name.n, &attr, a_avp)) { /* only signal error - continue */ LM_ERR("too many attribute names\n"); } raise: err = evi_raise_event(id, params); return err ? err : 1; error: evi_free_params(params); return -1; }
int ds_set_state(int group, str *address, int state, int type) { int i=0; ds_set_p idx = NULL; evi_params_p list = NULL; if(_ds_list==NULL || _ds_list_nr<=0) { LM_DBG("empty destination set\n"); return -1; } /* get the index of the set */ if(ds_get_index(group, &idx)!=0) { LM_ERR("destination set [%d] not found\n", group); return -1; } while(i<idx->nr) { if(idx->dlist[i].uri.len==address->len && strncasecmp(idx->dlist[i].uri.s, address->s, address->len)==0) { /* remove the Probing/Inactive-State? Set the fail-count to 0. */ if (state == DS_PROBING_DST) { if (type) { if (idx->dlist[i].flags & DS_INACTIVE_DST) { LM_INFO("Ignoring the request to set this destination" " to probing: It is already inactive!\n"); return 0; } idx->dlist[i].failure_count++; /* Fire only, if the Threshold is reached. */ if (idx->dlist[i].failure_count < probing_threshhold) return 0; if (idx->dlist[i].failure_count > probing_threshhold) idx->dlist[i].failure_count = probing_threshhold; } } /* Reset the Failure-Counter */ if ((state & DS_RESET_FAIL_DST) > 0) { idx->dlist[i].failure_count = 0; state &= ~DS_RESET_FAIL_DST; } if(type) idx->dlist[i].flags |= state; else idx->dlist[i].flags &= ~state; if (dispatch_evi_id == EVI_ERROR) { LM_ERR("event not registered %d\n", dispatch_evi_id); } else if (evi_probe_event(dispatch_evi_id)) { if (!(list = evi_get_params())) return 0; if (evi_param_add_int(list, &group_str, &group)) { LM_ERR("unable to add group parameter\n"); evi_free_params(list); return 0; } if (evi_param_add_str(list, &address_str, address)) { LM_ERR("unable to add address parameter\n"); evi_free_params(list); return 0; } if (evi_param_add_str(list, &status_str, type ? &inactive_str : &active_str)) { LM_ERR("unable to add status parameter\n"); evi_free_params(list); return 0; } if (evi_raise_event(dispatch_evi_id, list)) { LM_ERR("unable to send event\n"); } } else { LM_DBG("no event sent\n"); } return 0; } i++; } return -1; }