Jump to content

Adding New Function in Current Code


asterdeve

Recommended Posts

Viewers, Thanks for watching I hope one of you will help me soon, below is my function of Codeignitor.

function status()
{
$org = Array ( [0] => Response: Follows [1] => Privilege: Command [2] => Name/username Host Dyn Forcerport ACL Port Status [3] => Test-Call 198.15.126.41 5060 OK (256 ms) [4] => rutest/rutest (Unspecified) D 0 UNKNOWN [5] => simpro/simpro (Unspecified) D 0 UNKNOWN [6] => test2 79.115.39.65 5060 UNREACHABLE [7] => 4 sip peers [Monitored: 1 online, 3 offline Unmonitored: 0 online, 0 offline] [8] => --END COMMAND-- [9] => );

$this->db->where('status',1);
$query=$this->db->get('simpro_originator');
$results=$query->result_array();
foreach($results as $row)
{
$data[$i]['id']=$row['id'];
$data[$i]['name']=$row['name'];
$data[$i]['pass']=$row['pass'];
$data[$i]['orig_ip']=$row['orig_ip'];
$data[$i]['call_limit']=$row['call_limit'];
$data[$i]['status']=$row['status'];
$data[$i]['created_on']=$row['created_on'];
foreach($org as $str)
{

if(stripos($str,$row['orig_ip']))
{
if(stripos($str,'OK'))
{
$data[$i]['active']='OK';
}
else
$data[$i]['active']='NOTOK';
}
}

$i++;
}
print_r($data);
return data = {"":{"id":"1","name":"Test-Call","pass":"Google","orig_ip":"198.15.126.41","call_limit":"128","status":"1","created_on":"2018-01-14 08:04:44","active":"OK"},"1":{"id":"2","name":"test2","pass":"sfsdfsa","orig_ip":"79.115.39.65","call_limit":"64","status":"1","created_on":"2018-03-08 01:07:02","active":"NOTOK"}}
}
}
So as you can see I get active: OK or NOTOK, I want it will also show another array with name latency: Result or N/A, check on $org = which IP result is OK with that result there is latency OK (256 ms), so I want to get that result in array too without ( ) like this "active":"OK or NOTOK" & "latency":"256 ms or N/A"

I hope I clarified my question & someone will able to help me ASAP, Thanks in advance.

Link to comment
Share on other sites

That's clearly not the code you're using: it's not valid. The $org thing at the top and the data= bit at the bottom. PHP will refuse to execute the file containing this.

 

So what is the real code? If you need to get the latency from $org then we have to see what $org actually is.

Link to comment
Share on other sites

$org is asterisk AMI command I give you like this to make you understand better, we get data from asterisk exactly like this, & we want to view only one more things is that latency as I was mentioned on my question also.

Link to comment
Share on other sites

Okay then...

 

You have to figure out which of the $org lines contains the latency information. Your code already does that. Then you can use a regular expression to extract the value.

preg_match('/\((\d+) ms\)/', $str, $match)
Learn about preg_match and how to use it, then you can get the latency value from $match[1].
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.