Skip to content

Commit 21375dd

Browse files
add alarm to monitor trunk calls failed
1 parent e948747 commit 21375dd

File tree

9 files changed

+158
-77
lines changed

9 files changed

+158
-77
lines changed

build/MagnusBilling-current.tar.gz

113 Bytes
Binary file not shown.

classic/src/view/alarm/Form.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ Ext.define('MBilling.view.alarm.Form', {
3737
['4', t('Consecutive number')],
3838
['5', t('Online calls on same number')],
3939
['6', t('Same number and CallerID')],
40-
['7', t('Total calls per user')]
40+
['7', t('Total calls per user')],
41+
['8', t('Failed calls per trunk')]
4142
]
4243
}, {
4344
xtype: 'combobox',

classic/src/view/alarm/List.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ Ext.define('MBilling.view.alarm.List', {
5959
case 7:
6060
value = t('Total calls per user');
6161
break;
62+
case 8:
63+
value = t('Failed calls per trunk');
64+
break;
6265
}
6366
return value
6467
},

protected/commands/AlarmCommand.php

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public function run($args)
6363
# TOTAL CALLS PER USER
6464
$this->totalCallsPerUser($alarm);
6565
break;
66+
case 8:
67+
# TOTAL CALLS TRUNK FAIL
68+
$this->totalCallsTrunkFail($alarm);
69+
break;
6670
}
6771
}
6872
}
@@ -272,9 +276,48 @@ public function totalCallsPerUser($alarm)
272276
}
273277
}
274278

275-
public function notification($alarm)
279+
public function totalCallsTrunkFail($alarm)
276280
{
281+
if ($alarm->period < 1000 && $alarm->last_notification > date('Y-m-d')) {
282+
//interval more than 1 days, only send notification email 1 time per day
283+
return;
284+
}
285+
286+
$period = time() - $alarm->period;
287+
288+
$period = date("Y-m-d H:i:s", $period);
289+
290+
$this->filter = "starttime > '$period'";
291+
292+
$modelTrunk = Trunk::model()->findAll('status = 1');
293+
294+
foreach ($modelTrunk as $key => $trunk) {
295+
296+
$sql = "SELECT count(id) AS id FROM pkg_cdr_failed WHERE id_trunk = " . $trunk->id . " AND " . $this->filter;
297+
$modeCdr = Call::model()->findBySql($sql);
298+
299+
$calls = is_numeric($modeCdr->id) ? $modeCdr->id : 0;
277300

301+
echo $calls;
302+
303+
if ($alarm->condition == 1) {
304+
if ($modeCdr->id > $alarm->amount) {
305+
$alarm->message = preg_replace('/%trunk%/', $trunk->trunkcode, $alarm->message);
306+
$alarm->message = preg_replace('/%totalCalls%/', $modeCdr->id, $alarm->message);
307+
$this->notification($alarm);
308+
}
309+
} else if ($alarm->condition == 2) {
310+
if ($modeCdr->id < $alarm->amount) {
311+
$this->notification($alarm);
312+
}
313+
}
314+
315+
}
316+
317+
}
318+
319+
public function notification($alarm)
320+
{
278321
$condition = [
279322
1 => 'Bigger than',
280323
2 => 'Less than',
@@ -288,17 +331,9 @@ public function notification($alarm)
288331
5 => 'Online calls on same number',
289332
6 => 'Same number and CallerID',
290333
7 => 'Total calls per user',
334+
8 => 'Failed calls per trunk',
291335
];
292336

293-
$type = [
294-
1 => 'ALOC',
295-
2 => 'ASR',
296-
3 => 'Calls per minute',
297-
4 => 'Consecutive number',
298-
5 => 'Online calls on same number',
299-
6 => 'Same number and CallerID',
300-
7 => 'Total calls per user',
301-
];
302337
$period = [
303338
'3600' => '1 Hour',
304339
'7200' => '2 Hours',
@@ -334,7 +369,7 @@ public function notification($alarm)
334369

335370
$modelSmtps = Smtps::model()->find('id_user = 1');
336371

337-
if (!isset($modelSmtps->id)) {
372+
if ( ! isset($modelSmtps->id)) {
338373
return;
339374
}
340375
$smtp_host = $modelSmtps->host;
@@ -352,9 +387,9 @@ public function notification($alarm)
352387
}
353388

354389
$modelTemplate = TemplateMail::model()->find('fromemail != :key ',
355-
array(
390+
[
356391
':key' => '[email protected]',
357-
));
392+
]);
358393
$from_email = isset($modelTemplate->fromemail) ? $modelTemplate->fromemail : $smtp_username;
359394

360395
Yii::import('application.extensions.phpmailer.JPhpMailer');

protected/commands/BackupCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function run($args)
3333
$comando = "mysqldump -u" . $username . " -p" . $password . " " . $dataBase . " --no-data pkg_cdr_failed --no-data pkg_cdr_archive --no-data pkg_cdr_failed_archive --no-data pkg_call_chart --no-data pkg_status_system >> /tmp/base.sql";
3434
LinuxAccess::exec($comando);
3535

36-
LinuxAccess::exec("tar czvf /usr/local/src/magnus/backup/backup_voip_Magnus.$data.tgz /tmp/base.sql /etc/asterisk");
36+
LinuxAccess::exec("tar czvf /usr/local/src/magnus/backup/backup_voip_softswitch.$data.tgz /tmp/base.sql /etc/asterisk");
3737
LinuxAccess::exec("rm -f /tmp/base.sql");
3838
}
3939
}

protected/commands/PortabilidadeCommand.php

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@ class PortabilidadeCommand extends CConsoleCommand
2121
{
2222
public function run($args)
2323
{
24+
25+
if ($args[2] == 'did') {
26+
$this->checkDID($args);
27+
exit;
28+
}
29+
2430
shell_exec('mkdir -p /usr/src/ChipCerto');
2531
shell_exec('rm -rf /usr/src/ChipCerto/*');
2632
shell_exec('cd /usr/src/ChipCerto && wget ftp://' . $_SERVER['argv']['2'] . ':' . $_SERVER['argv']['3'] . '@ftp.portabilidadecelular.com:2157/portabilidade.tar.bz2 && tar -jxvf portabilidade.tar.bz2');
2733
shell_exec('cd /usr/src/ChipCerto && wget ftp://' . $_SERVER['argv']['2'] . ':' . $_SERVER['argv']['3'] . '@ftp.portabilidadecelular.com:2157/prefix_anatel.csv');
2834

29-
if (!file_exists("/usr/src/ChipCerto/prefix_anatel.csv")) {
35+
if ( ! file_exists("/usr/src/ChipCerto/prefix_anatel.csv")) {
3036
exit;
3137
}
3238

@@ -50,7 +56,7 @@ public function run($args)
5056
$sql = "LOAD DATA LOCAL INFILE '/usr/src/ChipCerto/prefix_anatel.csv' INTO TABLE pkg_portabilidade_prefix FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n' (number, company);";
5157
Yii::app()->db->createCommand($sql)->execute();
5258

53-
if (!file_exists("/usr/src/ChipCerto/exporta.csv")) {
59+
if ( ! file_exists("/usr/src/ChipCerto/exporta.csv")) {
5460
exit;
5561
}
5662

@@ -75,4 +81,40 @@ public function run($args)
7581
$sql = "LOAD DATA LOCAL INFILE '/usr/src/ChipCerto/exporta.csv' INTO TABLE pkg_portabilidade FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n' (id, number, company, date);";
7682
Yii::app()->db->createCommand($sql)->execute();
7783
}
84+
85+
public function checkDID($args)
86+
{
87+
88+
$modelDid = Did::model()->findAll();
89+
90+
foreach ($modelDid as $key => $did) {
91+
92+
$url = "https://consultas.portabilidadecelular.com/painel/consulta_numero.php?user=" . $args[0] . "&pass=" . $args[1] . "&seache_number=" . $did->did . "&completo";
93+
if ( ! $result = @file_get_contents($url, false)) {
94+
$did->country = 'Operadora não identificada';
95+
} else {
96+
$res = preg_split('/\|/', $result);
97+
}
98+
99+
if ($res == 55998) {
100+
$did->country = 'Sem crédito';
101+
} else {
102+
103+
if ( ! isset($res[1])) {
104+
print_r($result);
105+
continue;
106+
}
107+
if ($res[1]) {
108+
$did->country = $res[3] . ' ' . $res[2];
109+
} else {
110+
$did->country = $res[3];
111+
}
112+
}
113+
$did->country = utf8_encode($did->country);
114+
echo $did->did . ' ' . $did->country . "\n";
115+
116+
$did->save();
117+
118+
}
119+
}
78120
}

0 commit comments

Comments
 (0)