From 2750475ab208b522236684baed457a007d9344f2 Mon Sep 17 00:00:00 2001 From: markjcrane Date: Wed, 26 May 2021 14:29:46 -0600 Subject: [PATCH] Add better logging to XML CDR --- app/xml_cdr/resources/classes/xml_cdr.php | 73 ++++++++++++++--------- app/xml_cdr/xml_cdr_import.php | 4 +- core/default_settings/app_config.php | 16 +++++ 3 files changed, 63 insertions(+), 30 deletions(-) diff --git a/app/xml_cdr/resources/classes/xml_cdr.php b/app/xml_cdr/resources/classes/xml_cdr.php index 864fbaf287..a66b0ae534 100644 --- a/app/xml_cdr/resources/classes/xml_cdr.php +++ b/app/xml_cdr/resources/classes/xml_cdr.php @@ -37,7 +37,6 @@ if (!class_exists('xml_cdr')) { */ public $db; public $array; - public $debug; public $fields; /** @@ -95,13 +94,33 @@ if (!class_exists('xml_cdr')) { * cdr process logging */ public function log($message) { - //save to file system (alternative to a syslog server) - $fp = fopen($_SESSION['server']['temp']['dir'].'/xml_cdr.log', 'a+'); - if (!$fp) { - return; + + //save the log if enabled is true + if ($_SESSION['log']['enabled']['boolean'] == 'true') { + + //save the log to the php error log + if ($_SESSION['log']['type']['text'] == 'error_log') { + error_log($message); } - fwrite($fp, $message); - fclose($fp); + + //save the log to the syslog server + if ($_SESSION['log']['type']['text'] == 'syslog') { + openlog("XML CDR", LOG_PID | LOG_PERROR, LOG_LOCAL0); + syslog(LOG_WARNING, $message); + closelog(); + } + + //save the log to the file system + if ($_SESSION['log']['type']['text'] == 'file') { + $fp = fopen($_SESSION['server']['temp']['dir'].'/xml_cdr.log', 'a+'); + if (!$fp) { + return; + } + fwrite($fp, $message); + fclose($fp); + } + + } } /** @@ -214,8 +233,9 @@ if (!class_exists('xml_cdr')) { $database->app_uuid = '4a085c51-7635-ff03-f67b-86e834422848'; $database->domain_uuid = $domain_uuid; $database->save($array, false); - //$message = $database->message; - //print_r($message); + + //debug results + $this->log(print_r($database->message, true)); //remove the temporary permission $p->delete("xml_cdr_add", "temp"); @@ -255,7 +275,7 @@ if (!class_exists('xml_cdr')) { } catch(Exception $e) { echo $e->getMessage(); - //$this->log("\nfail loadxml: " . $e->getMessage() . "\n"); + $this->log("\nXML parsing error: " . $e->getMessage() . "\n"); } //check for duplicate call uuid's @@ -479,7 +499,7 @@ if (!class_exists('xml_cdr')) { } //send the domain name to the cdr log - //$this->log("\ndomain_name is `$domain_name`; domain_uuid is '$domain_uuid'\n"); + //$this->log("\ndomain_name is `$domain_name`;\ndomain_uuid is '$domain_uuid'\n"); //get the domain_uuid with the domain_name if (strlen($domain_uuid) == 0) { @@ -713,10 +733,9 @@ if (!class_exists('xml_cdr')) { } //insert the values - if ($this->debug) { - //$time5_insert = microtime(true); - //echo $sql."
\n"; - } + //if ($this->debug) { + // $time5_insert = microtime(true); + //} try { $error = "false"; //$this->db->exec($sql); @@ -737,9 +756,10 @@ if (!class_exists('xml_cdr')) { fwrite($fh, json_encode($xml)); } fclose($fh); - if ($this->debug) { - echo $e->getMessage(); - } + + //debug info + $this->log($e->getMessage()); + $error = "true"; } @@ -764,11 +784,10 @@ if (!class_exists('xml_cdr')) { } unset($error); - //if ($this->debug) { - //GLOBAL $insert_time,$insert_count; - //$insert_time+=microtime(true)-$time5_insert; //add this current query. - //$insert_count++; - //} + //debug + //GLOBAL $insert_time,$insert_count; + //$insert_time+=microtime(true)-$time5_insert; //add this current query. + //$insert_count++; } //if ($duplicate_uuid == false) } //function xml_array @@ -850,10 +869,9 @@ if (!class_exists('xml_cdr')) { */ public function post() { if (isset($_POST["cdr"])) { + //debug method - if ($this->debug){ - print_r($_POST["cdr"]); - } + //$this->log($_POST["cdr"]); //authentication for xml cdr http post if (!defined('STDIN')) { @@ -925,11 +943,12 @@ if (!class_exists('xml_cdr')) { } //log the xml cdr - //xml_cdr_log("process cdr via post\n"); + $this->log("HTTP POST\n"); //parse the xml and insert the data into the database $this->xml_array(0, $leg, $xml_string); $this->save(); + } } //$this->post(); diff --git a/app/xml_cdr/xml_cdr_import.php b/app/xml_cdr/xml_cdr_import.php index 14cb583a19..94d4666297 100644 --- a/app/xml_cdr/xml_cdr_import.php +++ b/app/xml_cdr/xml_cdr_import.php @@ -44,11 +44,9 @@ ini_set('memory_limit', '256M'); ini_set("precision", 6); -//import the call detail records +//import the call detail records from HTTP POST or file system $cdr = new xml_cdr; - //import from the FreeSWITCH POST $cdr->post(); - //import from the file system $cdr->read_files(); ?> diff --git a/core/default_settings/app_config.php b/core/default_settings/app_config.php index e53c918856..fb260d5e8b 100644 --- a/core/default_settings/app_config.php +++ b/core/default_settings/app_config.php @@ -453,6 +453,22 @@ $apps[$x]['default_settings'][$y]['default_setting_value'] = "/var/cache/fusionpbx"; $apps[$x]['default_settings'][$y]['default_setting_enabled'] = "true"; $apps[$x]['default_settings'][$y]['default_setting_description'] = "Location for the file cache."; + $y++; + $apps[$x]['default_settings'][$y]['default_setting_uuid'] = "31b60c5f-e501-4982-893b-b56ef4ef5b56"; + $apps[$x]['default_settings'][$y]['default_setting_category'] = "log"; + $apps[$x]['default_settings'][$y]['default_setting_subcategory'] = "enabled"; + $apps[$x]['default_settings'][$y]['default_setting_name'] = "boolean"; + $apps[$x]['default_settings'][$y]['default_setting_value'] = "false"; + $apps[$x]['default_settings'][$y]['default_setting_enabled'] = "true"; + $apps[$x]['default_settings'][$y]['default_setting_description'] = "Enable logging true or false."; + $y++; + $apps[$x]['default_settings'][$y]['default_setting_uuid'] = "81008738-aec1-4535-b451-29c25f213694"; + $apps[$x]['default_settings'][$y]['default_setting_category'] = "log"; + $apps[$x]['default_settings'][$y]['default_setting_subcategory'] = "type"; + $apps[$x]['default_settings'][$y]['default_setting_name'] = "text"; + $apps[$x]['default_settings'][$y]['default_setting_value'] = "syslog"; + $apps[$x]['default_settings'][$y]['default_setting_enabled'] = "true"; + $apps[$x]['default_settings'][$y]['default_setting_description'] = "Options: syslog, file"; //schema details $y=0;