You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
res_alarmsystem: Fix breach reporting in phone-only mode.
BREACH was an "inferred" event in IP reporting mode, but can't
be inferred if reporting by phone (or if IP has failed). The
overhead of reporting by IP is small, so always report it from
now on so that way it works properly in any configuration.
The breach event was getting skipped
Also, breach reporting could be delayed by as much as the
ping interval; take the floor of the two so that we report
breaches as soon as they occur.
* and that would unnecessarily increment every few seconds. */
1324
-
c->sequence_no++;
1328
+
if (event==EVENT_PING) {
1329
+
AST_LIST_UNLOCK(&c->events);
1330
+
/* Send the event directly via UDP now, and don't store it in the queue,
1331
+
* since we'll keep retrying pings on a timer, no need to retry specific pings.
1332
+
* Since it's UDP, this won't block.
1333
+
* Also, we attempt pings regardless of the value of c->ip_connected.
1334
+
* No way to know if the connection is back without constantly retrying. */
1335
+
send_event_ip(c, msgbuf, len);
1336
+
return0;
1325
1337
}
1326
1338
1327
1339
/* If there is dialplan to execute for this event, do it async now */
@@ -1330,46 +1342,40 @@ static int generate_event(struct alarm_client *c, enum alarm_event_type event, s
1330
1342
}
1331
1343
1332
1344
/* Certain events aren't actually sent across the wire, they can be inferred by the server */
1333
-
if (INFERRED_EVENT(event)) {
1345
+
if (!NEED_TO_SEND_EVENT(c, event)) {
1334
1346
AST_LIST_UNLOCK(&c->events);
1347
+
ast_debug(10, "Dropping event (can be inferred by server)\n");
1335
1348
return0;
1336
1349
}
1337
1350
1338
-
if (event==EVENT_PING) {
1351
+
if (c->sfd==-1&&c->server_dialstr[0] =='\0') {
1352
+
/* IP and phone are disabled, so we can't report to any server. */
1339
1353
AST_LIST_UNLOCK(&c->events);
1340
-
/* Send the event directly via UDP now, and don't store it in the queue,
1341
-
* since we'll keep retrying pings on a timer, no need to retry specific pings.
1342
-
* Since it's UDP, this won't block.
1343
-
* Also, we attempt pings regardless of the value of c->ip_connected.
1344
-
* No way to know if the connection is back without constantly retrying. */
1345
-
send_event_ip(c, msgbuf, len);
1346
-
} else {
1347
-
if (c->sfd==-1&&c->server_dialstr[0] =='\0') {
1348
-
/* IP and phone are disabled, so we can't report to any server. */
1349
-
AST_LIST_UNLOCK(&c->events);
1350
-
return1;
1351
-
}
1352
-
/* Add the event to the send queue for guaranteed FIFO delivery. */
1353
-
e=ast_calloc(1, sizeof(*e) +len+1);
1354
-
if (!e) {
1355
-
AST_LIST_UNLOCK(&c->events);
1356
-
ast_log(LOG_ERROR, "Failed to add message to send queue\n");
1357
-
return-1;
1358
-
}
1359
-
strcpy(e->data, msgbuf); /* Safe */
1360
-
e->encoded=e->data;
1361
-
e->seqno=sequence_no;
1362
-
AST_LIST_INSERT_TAIL(&c->events, e, entry);
1354
+
return1;
1355
+
}
1356
+
/* Add the event to the send queue for guaranteed FIFO delivery. */
1357
+
e=ast_calloc(1, sizeof(*e) +len+1);
1358
+
if (!e) {
1359
+
AST_LIST_UNLOCK(&c->events);
1360
+
ast_log(LOG_ERROR, "Failed to add message to send queue\n");
1361
+
return-1;
1362
+
}
1363
+
strcpy(e->data, msgbuf); /* Safe */
1364
+
e->encoded=e->data;
1365
+
e->seqno=sequence_no;
1366
+
AST_LIST_INSERT_TAIL(&c->events, e, entry);
1363
1367
1364
-
if (event==EVENT_ALARM_BREACH) {
1365
-
c->flush_messages |= FLUSH_BREACH; /* Normally if batch reporting is enabled, messages are queued and not reported in realtime, but breaches trigger immediate reporting */
1366
-
}
1368
+
if (event==EVENT_ALARM_BREACH) {
1369
+
c->flush_messages |= FLUSH_BREACH; /* Normally if batch reporting is enabled, messages are queued and not reported in realtime, but breaches trigger immediate reporting */
1370
+
/* Reset the phone sync failure counter as we want to try immediately to report this,
1371
+
* even if we were previously unable to report by phone successfully. */
1372
+
c->consecutive_failed_phonesyncs=0;
1373
+
}
1367
1374
1368
-
/* Wake up the client thread to tell it to send the message */
1369
-
ast_alertpipe_write(c->alertpipe);
1375
+
/* Wake up the client thread to tell it to send the message */
1376
+
ast_alertpipe_write(c->alertpipe);
1370
1377
1371
-
AST_LIST_UNLOCK(&c->events);
1372
-
}
1378
+
AST_LIST_UNLOCK(&c->events);
1373
1379
return0;
1374
1380
}
1375
1381
@@ -1688,7 +1694,7 @@ static int send_events_to_server_by_phone(struct alarm_client *c)
1688
1694
}
1689
1695
1690
1696
/* Wait for initial ACK from AlarmEventReceiver to synchronize */
0 commit comments