Skip to content

Commit

Permalink
fraud_detection: add profile id to the raised events
Browse files Browse the repository at this point in the history
  • Loading branch information
greenbea committed Sep 11, 2024
1 parent 105d7ce commit 16860fa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
6 changes: 6 additions & 0 deletions modules/fraud_detection/doc/fraud_detection_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,9 @@ modparam("fraud_detection", "seqcalls_thresh_crit_col", "seqcalls_crit_thresh")
<emphasis>rule_id</emphasis> - the id of the fraud rule that matched
when the call was initiated
</para></listitem>
<listitem><para>
<emphasis>profile_id</emphasis> - the profile id used
</para></listitem>
</itemizedlist>
</section>
<section id="event_E_FRD_CRITICAL" xreflabel="E_FRD_CRITICAL">
Expand Down Expand Up @@ -711,6 +714,9 @@ modparam("fraud_detection", "seqcalls_thresh_crit_col", "seqcalls_crit_thresh")
<listitem><para>
<emphasis>rule_id</emphasis> - the id of the fraud rule that matched
when the call was initiated
</para></listitem>
<listitem><para>
<emphasis>profile_id</emphasis> - the profile id used
</para></listitem>
</itemizedlist>
</section>
Expand Down
3 changes: 2 additions & 1 deletion modules/fraud_detection/fraud_detection.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ static int check_fraud(struct sip_msg *msg, str *user, str *number, int *pid)
#define CHECK_AND_RAISE(pname, type) \
(thr->pname ## _thr.type && se->stats.pname >= thr->pname ## _thr.type) { \
raise_ ## type ## _event(&pname ## _name, &se->stats.pname,\
&thr->pname ## _thr.type, user, number, &rule->id);\
&thr->pname ## _thr.type, user, number, &rule->id, pid);\
rc = rc_ ## type ## _thr;\
}

Expand Down Expand Up @@ -429,6 +429,7 @@ static int check_fraud(struct sip_msg *msg, str *user, str *number, int *pid)
param->stats = se; /* safe to ref, only freed @ shutdown */
param->user = shm_user; /* safe to ref, only freed @ shutdown */
param->ruleid = rule->id;
param->pid = *pid;
param->dlg_terminated = 0;

param->calldur_warn = thr->call_duration_thr.warning;
Expand Down
19 changes: 11 additions & 8 deletions modules/fraud_detection/frd_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ static str ei_thr_name = str_init("threshold");
static str ei_user_name = str_init("user");
static str ei_number_name = str_init("called_number");
static str ei_ruleid_name = str_init("rule_id");
static str ei_pid_name = str_init("profile_id");

static evi_param_p param_p, val_p, thr_p, user_p, number_p, ruleid_p;
static evi_param_p param_p, val_p, thr_p, user_p, number_p, ruleid_p, pid_p;


/*
Expand Down Expand Up @@ -87,6 +88,7 @@ int frd_event_init(void)
CREATE_PARAM(user);
CREATE_PARAM(number);
CREATE_PARAM(ruleid);
CREATE_PARAM(pid);
#undef CREATE_PARAM

return 0;
Expand All @@ -106,7 +108,7 @@ void frd_event_destroy(void)
*/
static void raise_event(event_id_t e,
str *param, unsigned int *val, unsigned int *thr, str *user,
str *number, unsigned int *ruleid)
str *number, unsigned int *ruleid, int *pid)
{
#define SET_PARAM(pname, ptype) \
if (evi_param_set_ ##ptype (pname ## _p, pname) < 0) { \
Expand All @@ -120,22 +122,23 @@ static void raise_event(event_id_t e,
SET_PARAM(user, str);
SET_PARAM(number, str);
SET_PARAM(ruleid, int);
SET_PARAM(pid, int);
#undef SET_PARAM

if (evi_raise_event(e, event_params) < 0)
LM_ERR("cannot raise event\n");
}

void raise_warning_event(str *param, unsigned int *val, unsigned int *thr,
str *user, str *number, unsigned int *ruleid)
str *user, str *number, unsigned int *ruleid, int *pid)
{
raise_event(ei_warn_id, param, val, thr, user, number, ruleid);
raise_event(ei_warn_id, param, val, thr, user, number, ruleid, pid);
}

void raise_critical_event(str *param, unsigned int *val, unsigned int *thr,
str *user, str *number, unsigned int *ruleid)
str *user, str *number, unsigned int *ruleid, int *pid)
{
raise_event(ei_crit_id, param, val, thr, user, number, ruleid);
raise_event(ei_crit_id, param, val, thr, user, number, ruleid, pid);
}


Expand Down Expand Up @@ -163,13 +166,13 @@ void dialog_terminate_CB(struct dlg_cell *dlg, int type,
&& duration >= frdparam->calldur_crit)
raise_critical_event(&call_dur_name, &duration,
&frdparam->calldur_crit,
&frdparam->user, &frdparam->number, &frdparam->ruleid);
&frdparam->user, &frdparam->number, &frdparam->ruleid, &frdparam->pid);

else if (!(type & DLGCB_FAILED) && frdparam->calldur_warn
&& duration >= frdparam->calldur_warn)
raise_warning_event(&call_dur_name, &duration,
&frdparam->calldur_warn,
&frdparam->user, &frdparam->number, &frdparam->ruleid);
&frdparam->user, &frdparam->number, &frdparam->ruleid, &frdparam->pid);

lock_get(&frdparam->stats->lock);
if (!frdparam->dlg_terminated
Expand Down
5 changes: 3 additions & 2 deletions modules/fraud_detection/frd_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
int frd_event_init(void);
void frd_event_destroy(void);
void raise_warning_event(str *param, unsigned int *val, unsigned int *thr,
str *user, str *number, unsigned int *ruleid);
str *user, str *number, unsigned int *ruleid, int *pid);
void raise_critical_event(str *param, unsigned int *val, unsigned int *thr,
str *user, str *number, unsigned int *ruleid);
str *user, str *number, unsigned int *ruleid, int *pid);


/* Dialog callback */
Expand All @@ -44,6 +44,7 @@ typedef struct {
str user;
str number;
unsigned int ruleid;
int pid;
unsigned int interval_id;

unsigned int calldur_warn;
Expand Down

0 comments on commit 16860fa

Please sign in to comment.