Skip to content

Commit 63db46a

Browse files
author
magnussolution
committed
slave monitor
1 parent d98ca62 commit 63db46a

File tree

11 files changed

+67
-13
lines changed

11 files changed

+67
-13
lines changed

app/helper/Util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ Ext.define('Helper.Util', {
587587
formatBooleanServers: function(value) {
588588
var me = Helper.Util,
589589
color = value == 0 ? 'red' : value == 1 ? 'green' : value == 2 ? '#FFCC00' : '#FFCC00',
590-
value = value == 0 ? t('Inactive') : value == 1 ? t('Active') : value == 2 ? t('OffLine') : t('Pending');
590+
value = value == 0 ? t('Inactive') : value == 1 ? t('Active') : value == 2 ? t('OffLine') : value == 3 ? t('Error') : value == 4 ? t('Alert') : t('Pending');
591591
return '<span style="color:' + color + '">' + value + '</span>';
592592
},
593593
formatLanguageImage: function(value) {

build/MagnusBilling-current.tar.gz

-101 Bytes
Binary file not shown.

classic/src/view/servers/Form.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ Ext.define('MBilling.view.servers.Form', {
7979
store: [
8080
[1, t('Active')],
8181
[0, t('Inactive')],
82-
[2, t('OffLine')]
82+
[2, t('OffLine')],
83+
[4, t('Alert')]
8384
]
8485
}, {
8586
xtype: 'fieldset',

classic/src/view/servers/List.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ Ext.define('MBilling.view.servers.List', {
6262
options: [
6363
[1, t('Active')],
6464
[0, t('Inactive')],
65-
[2, t('OffLine')]
65+
[2, t('OffLine')],
66+
[4, t('Alert')]
6667
]
6768
}
6869
}]

protected/commands/SipProxyAccountsCommand.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ class SipProxyAccountsCommand extends ConsoleCommand
2323
public function run($args)
2424
{
2525

26+
$modelServers = Servers::model()->findAll('type = "asterisk" AND status IN (1,3,4) AND weight > 0');
27+
foreach ($modelServers as $key => $server) {
28+
if ($server->last_call_id > 0) {
29+
$modelCall = Call::model()->findBySql('SELECT id,starttime FROM pkg_cdr WHERE id > :key1 AND id_server = :key ORDER BY id DESC LIMIT 1', array(
30+
'key' => $server->id,
31+
':key1' => $server->last_call_id,
32+
));
33+
} else {
34+
$modelCall = Call::model()->findBySql('SELECT id,starttime FROM pkg_cdr WHERE starttime > :key1 AND id_server = :key LIMIT 1', array(
35+
'key' => $server->id,
36+
':key1' => date('Y-m-d'),
37+
));
38+
}
39+
if (isset($modelCall->id)) {
40+
$server->last_call = $modelCall->starttime;
41+
$server->last_call_id = $modelCall->id;
42+
$server->save();
43+
}
44+
}
45+
2646
$modelSip = Sip::model()->findAll();
2747
$modelTrunk = Trunk::model()->findAll();
2848
$modelDid = Did::model()->findAll('activated = 1 AND reserved > 0 AND id_server > 0');
@@ -80,9 +100,7 @@ public function run($args)
80100
//
81101
}
82102
foreach ($modelSip as $key => $sip) {
83-
if ($sip->idUser->active == 0) {
84-
continue;
85-
}
103+
86104
if ($sip->host == 'dynamic') {
87105
$sqlproxy .= " ('" . $sip->defaultuser . "', '$remoteProxyIP','" . $sip->secret . "','" . md5($sip->defaultuser . ':' . $remoteProxyIP . ':' . $sip->secret) . "', '" . $sip->idUser->username . "', '" . $sip->trace . "','" . $sip->idUser->cpslimit . "'),";
88106
} else {

protected/commands/UpdateMysqlCommand.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,6 +1938,18 @@ public function run($args)
19381938
$version = '7.8.3.9';
19391939
$this->update($version);
19401940
}
1941+
1942+
//2023-06-26
1943+
if ($version == '7.8.3.9') {
1944+
$sql = "ALTER TABLE `pkg_servers` ADD `last_call` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP";
1945+
$this->executeDB($sql);
1946+
1947+
$sql = "ALTER TABLE `pkg_servers` ADD `last_call_id` INT(11) NULL DEFAULT NULL;";
1948+
$this->executeDB($sql);
1949+
1950+
$version = '7.8.4.0';
1951+
$this->update($version);
1952+
}
19411953
}
19421954

19431955
public function executeDB($sql)

protected/controllers/CallOnLineController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function setAttributesModels($attributes, $models)
164164

165165
if (isset($attributes[0])) {
166166
$modelSip = Sip::model()->findAll();
167-
$modelServers = Servers::model()->findAll('type != :key1 AND status = 1 AND host != :key', [':key' => 'localhost', ':key1' => 'sipproxy']);
167+
$modelServers = Servers::model()->findAll('type != :key1 AND status IN (1,4) AND host != :key', [':key' => 'localhost', ':key1' => 'sipproxy']);
168168

169169
if (!isset($modelServers[0])) {
170170
array_push($modelServers, array(

protected/controllers/ServersController.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,27 @@ public function init()
3737
parent::init();
3838
}
3939

40+
public function setAttributesModels($attributes, $models)
41+
{
42+
$modelServer = Servers::model()->find([
43+
'condition' => 'type = "asterisk" AND status = 1 AND weight > 0',
44+
'order' => 'last_call DESC',
45+
]);
46+
$last_call = date("Y-m-d H:i:s", strtotime("-5 minutes", strtotime($modelServer->last_call)));
47+
48+
$pkCount = is_array($attributes) || is_object($attributes) ? $attributes : [];
49+
for ($i = 0; $i < count($pkCount); $i++) {
50+
51+
if ($attributes[$i]['status'] == 4) {
52+
Servers::model()->updateByPk($attributes[$i]['id'], array('status' => 1));
53+
}
54+
if ($attributes[$i]['type'] == 'asterisk' && $attributes[$i]['status'] > 0 && $attributes[$i]['weight'] > '0' && $attributes[$i]['last_call'] < $last_call) {
55+
Servers::model()->updateByPk($attributes[$i]['id'], array('status' => 4));
56+
}
57+
}
58+
return $attributes;
59+
}
60+
4061
public function afterSave($model, $values)
4162
{
4263

@@ -69,7 +90,7 @@ public function afterSave($model, $values)
6990
foreach ($modelServerAS as $key => $server) {
7091

7192
$modelServer = Servers::model()->find("id = :key AND (type = 'asterisk' OR type = 'mbilling')
72-
AND status = 1 AND weight > 0", [':key' => $server->id_server]);
93+
AND status IN( 1,4) AND weight > 0", [':key' => $server->id_server]);
7394

7495
if (isset($modelServer->id)) {
7596
if ($this->ip_is_private($hostname)) {
@@ -90,7 +111,7 @@ public function afterSave($model, $values)
90111
} else {
91112

92113
$modelServerAS = Servers::model()->findAll("(type = 'asterisk' OR type = 'mbilling')
93-
AND status = 1 AND weight > 0");
114+
AND status IN( 1,4) AND weight > 0");
94115
foreach ($modelServerAS as $key => $server) {
95116

96117
if ($this->ip_is_private($hostname)) {

protected/controllers/VoucherController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ public function extraFilterCustom($filter)
137137

138138
if (Yii::app()->session['user_type'] == 3) {
139139
$filter .= ' AND t.id_user = :dfby';
140-
}
141140

142-
$this->paramsFilter[':dfby'] = Yii::app()->session['id_user'];
141+
$this->paramsFilter[':dfby'] = Yii::app()->session['id_user'];
142+
}
143143

144144
return $filter;
145145
}

protected/models/Servers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public function rules()
5656
{
5757
$rules = array(
5858
array('host', 'required'),
59-
array('status, weight', 'numerical', 'integerOnly' => true),
59+
array('status, weight, last_call_id', 'numerical', 'integerOnly' => true),
6060
array('host,name', 'length', 'max' => 100),
6161
array('description', 'length', 'max' => 500),
62-
array('password, username', 'length', 'max' => 50),
62+
array('password, username, last_call', 'length', 'max' => 50),
6363
array('type, port, sip_port', 'length', 'max' => 20),
6464
array('public_ip', 'length', 'max' => 80),
6565
array('password', 'checkpassword'),

0 commit comments

Comments
 (0)