예제 #1
0
function email_notify($check,$check_result,$subscription) {
 global $status_array;
 $user = new User($subscription->getUserId());
 echo 'email plugin!';
 $email = new fEmail();
 // This sets up fSMTP to connect to the gmail SMTP server
 // with a 5 second timeout. Gmail requires a secure connection.
 $smtp = new fSMTP('smtp.gmail.com', 465, TRUE, 5);
 $smtp->authenticate('*****@*****.**', 'example');
 $email->addRecipient($user->getEmail(), $user->getUsername());
 // Set who the email is from
 $email->setFromEmail('*****@*****.**','Tattle');
 // Set the subject include UTF-8 curly quotes
 $email->setSubject('Tattle : Alert for ' . $check->prepareName());
 // Set the body to include a string containing UTF-8
 $state = $status_array[$check_result->getStatus()];
 $email->setHTMLBody("<p>$state Alert for {$check->prepareName()} </p><p>The check returned {$check_result->prepareValue()}</p><p>Warning Threshold is : ". $check->getWarn() . "</p><p>Error Threshold is : ". $check->getError() . '</p><p>View Alert Details : <a href="' . $fURL::getDomain() . '/' . CheckResult::makeURL('list',$check_result) . '">'.$check->prepareName()."</a></p>");
 $email->setBody("
$state Alert for {$check->prepareName()}
The check returned {$check_result->prepareValue()}
Warning Threshold is : ". $check->getWarn() . "
Error Threshold is : ". $check->getError() . "
           ");
 try {  
   $message_id = $email->send($smtp);
 } catch ( fConnectivityException $e) { 
   fCore::debug("email send failed",FALSE);
 }


}
예제 #2
0
function email_plugin_notify($check,$check_result,$subscription,$alt_email=false) {
  global $status_array;
  $user = new User($subscription->getUserId());
  $email = new fEmail();
  // This sets up fSMTP to connect to the gmail SMTP server
  // with a 5 second timeout. Gmail requires a secure connection.
  $smtp = new fSMTP(sys_var('smtp_server'), sys_var('smtp_port'), TRUE, 5);
  $smtp->authenticate(sys_var('smtp_user'), sys_var('smtp_pass'));
  if ($alt_email) {
    $email_address = usr_var('alt_email',$user->getUserId());
  } else {
    $email_address = $user->getEmail(); 
  }
  $email->addRecipient($email_address, $user->getUsername());
  // Set who the email is from
  $email->setFromEmail(sys_var('email_from'), sys_var('email_from_display'));
  // Set the subject include UTF-8 curly quotes
  $email->setSubject(str_replace('{check_name}', $check->prepareName(), sys_var('email_subject')));
  // Set the body to include a string containing UTF-8
  $state = $status_array[$check_result->getStatus()];
  $email->setHTMLBody("<p>$state Alert for {$check->prepareName()} </p><p>The check returned {$check_result->prepareValue()}</p><p>Warning Threshold is : ". $check->getWarn() . "</p><p>Error Threshold is : ". $check->getError() . '</p><p>View Alert Details : <a href="' . fURL::getDomain() . '/' . CheckResult::makeURL('list',$check_result) . '">'.$check->prepareName()."</a></p>");
  $email->setBody("
  $state Alert for {$check->prepareName()}
The check returned {$check_result->prepareValue()}
Warning Threshold is : ". $check->getWarn() . "
Error Threshold is : ". $check->getError() . "
           ");
  try {  
    $message_id = $email->send($smtp);
  } catch ( fConnectivityException $e) { 
    fCore::debug("email send failed",FALSE);
  }
}
예제 #3
0
 /**
  * @dataProvider debugProvider
  */
 public function testDebug($value, $force, $global, $expected_output)
 {
     ob_start();
     if ($global) {
         fCore::enableDebugging(TRUE);
     }
     fCore::debug($value, $force);
     $output = ob_get_clean();
     $this->assertEquals($expected_output, rtrim($output, "\n"));
 }
예제 #4
0
function hipchat_master_notify($check, $check_result, $subscription, $toUser = true)
{
    global $status_array;
    global $debug;
    if (!is_callable('curl_init')) {
        fCore::debug("!!! WARNING !!! function curl_init() not found, probably php-curl is not installed");
    }
    $state = $status_array[$check_result->getStatus()];
    if (strtolower($state) == 'ok') {
        $color = sys_var('hipchat_ok_color');
    } elseif (strtolower($state) == 'warning') {
        $color = sys_var('hipchat_warning_color');
    } elseif (strtolower($state) == 'error') {
        $color = sys_var('hipchat_error_color');
    }
    $url = $GLOBALS['TATTLE_DOMAIN'] . '/' . CheckResult::makeURL('list', $check_result);
    $data = array('color' => $color, 'notify' => sys_var('hipchat_notify') == 'true' ? true : false, 'message_format' => 'html', 'message' => "<b>" . $check->prepareName() . "</b><br />The check returned: {$check_result->getValue()}<br />View Alert Details : <a href=\"" . $url . "\">" . $url . "</a>");
    if ($debug && $toUser == false) {
        $url = 'https://api.hipchat.com/v2/room?auth_token=' . sys_var('hipchat_apikey');
        $c = curl_init();
        curl_setopt($c, CURLOPT_URL, $url);
        curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
        fCore::debug("Rooms: " . curl_exec($c) . "\n", FALSE);
        fCore::debug("URL: " . 'https://api.hipchat.com/v2/room/' . strtolower(sys_var('hipchat_room')) . '/notification?auth_token=' . sys_var('hipchat_apikey') . "\n", FALSE);
        fCore::debug("Data: " . print_r($data, true) . "\n", FALSE);
    }
    if ($toUser == false) {
        $url = 'https://api.hipchat.com/v2/room/' . strtolower(sys_var('hipchat_room')) . '/notification?auth_token=' . sys_var('hipchat_apikey');
    } else {
        $url = 'https://api.hipchat.com/v2/user/' . usr_var('hipchat_user', $subscription->getUserId()) . '/message?auth_token=' . sys_var('hipchat_apikey');
    }
    fCore::debug("HipChat Calling: {$url}", FALSE);
    $c = curl_init();
    curl_setopt($c, CURLOPT_URL, $url);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($c, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen(json_encode($data))));
    curl_setopt($c, CURLOPT_POSTFIELDS, json_encode($data));
    $response = curl_exec($c);
    if ($response === false) {
        fCore::debug("Curl error: " . curl_error($c) . "\n", FALSE);
    }
    echo "\n\nResponse: " . curl_getinfo($c, CURLINFO_HTTP_CODE) . ' - ' . $response . "\n\n";
}
 /**
  * Translates Flourish SQL into the dialect for the current database
  * 
  * @internal
  * 
  * @param  array $statements  The SQL statements to translate
  * @return array  The translated SQL statements all ready for execution. Statements that have been translated will have string key of the number, `:` and the original SQL, all other will have a numeric key.
  */
 public function translate($statements)
 {
     $output = array();
     foreach ($statements as $number => $sql) {
         // These fixes don't need to know about strings
         $new_sql = $this->translateBasicSyntax($sql);
         if (in_array($this->database->getType(), array('mssql', 'oracle', 'db2'))) {
             $new_sql = $this->translateLimitOffsetToRowNumber($new_sql);
         }
         // SQL Server does not like to give unicode results back to PHP without some coersion
         if ($this->database->getType() == 'mssql') {
             $new_sql = $this->fixMSSQLNationalColumns($new_sql);
         }
         // Oracle has this nasty habit of silently translating empty strings to null
         if ($this->database->getType() == 'oracle') {
             $new_sql = $this->fixOracleEmptyStrings($new_sql);
         }
         $extra_statements = array();
         $new_sql = $this->translateCreateTableStatements($new_sql, $extra_statements);
         if ($sql != $new_sql || $extra_statements) {
             fCore::debug(self::compose("Original SQL:%s", "\n" . $sql), $this->debug);
             $translated_sql = $new_sql;
             if ($extra_statements) {
                 $translated_sql .= '; ' . join('; ', $extra_statements);
             }
             fCore::debug(self::compose("Translated SQL:%s", "\n" . $translated_sql), $this->debug);
         }
         $output = array_merge($output, array($number . ':' . $sql => $new_sql), $extra_statements);
     }
     return $output;
 }
예제 #6
0
 /**
  * Runs a single query and times it, removes any old unbuffered queries before starting
  * 
  * @param  string $sql          The SQL statement to execute
  * @param  string $result_type  The type of result object to return, fResult or fUnbufferedResult
  * @return fResult|fUnbufferedResult  The result for the query
  */
 private function runQuery($sql, $result_type)
 {
     if ($this->unbuffered_result) {
         $this->unbuffered_result->__destruct();
         $this->unbuffered_result = NULL;
     }
     $start_time = microtime(TRUE);
     if (!($result = $this->handleTransactionQueries($sql, $result_type))) {
         $result = new $result_type($this, $this->type == 'mssql' ? $this->schema_info['character_set'] : NULL);
         $result->setSQL($sql);
         if ($result_type == 'fResult') {
             $this->executeQuery($result);
         } else {
             $this->executeUnbufferedQuery($result);
         }
     }
     // Write some debugging info
     $query_time = microtime(TRUE) - $start_time;
     $this->query_time += $query_time;
     fCore::debug(self::compose('Query time was %1$s seconds for:%2$s', $query_time, "\n" . $result->getSQL()), $this->debug);
     if ($this->slow_query_threshold && $query_time > $this->slow_query_threshold) {
         trigger_error(self::compose('The following query took %1$s milliseconds, which is above the slow query threshold of %2$s:%3$s', $query_time, $this->slow_query_threshold, "\n" . $result->getSQL()), E_USER_WARNING);
     }
     return $result;
 }
예제 #7
0
 /**
  * Sends commands to the IMAP or POP3 server
  * 
  * @param  string  $command   The command to send
  * @param  integer $expected  The number of lines or regex expected for a POP3 command
  * @return array  The response from the server
  */
 private function write($command, $expected = NULL)
 {
     if (!$this->connection) {
         throw new fProgrammerException('Unable to send data since the connection has already been closed');
     }
     if ($this->type == 'imap') {
         $identifier = 'a' . str_pad($this->command_num++, 4, '0', STR_PAD_LEFT);
         $command = $identifier . ' ' . $command;
     }
     if (substr($command, -2) != "\r\n") {
         $command .= "\r\n";
     }
     if (fCore::getDebug($this->debug)) {
         fCore::debug("Sending:\n" . trim($command), $this->debug);
     }
     $res = fwrite($this->connection, $command);
     if ($res === FALSE) {
         throw new fConnectivityException('Unable to write data to %1$s server %2$s on port %3$s', strtoupper($this->type), $this->host, $this->port);
     }
     if ($this->type == 'imap') {
         return $this->read('#^' . $identifier . '#');
     } elseif ($this->type == 'pop3') {
         return $this->read($expected);
     }
 }
예제 #8
0
 /**
  * Translates Flourish SQL into the dialect for the current database
  * 
  * @internal
  * 
  * @param  array $statements            The SQL statements to translate
  * @param  array &$rollback_statements  SQL statements to rollback the returned SQL statements if something goes wrong - only applicable for MySQL `ALTER TABLE` statements
  * @return array  The translated SQL statements all ready for execution. Statements that have been translated will have string key of the number, `:` and the original SQL, all other will have a numeric key.
  */
 public function translate($statements, &$rollback_statements = NULL)
 {
     $output = array();
     foreach ($statements as $number => $sql) {
         $new_sql = $this->translateBasicSyntax($sql);
         $new_sql = $this->translateCastClauses($new_sql);
         if (in_array($this->database->getType(), array('mssql', 'oracle', 'db2'))) {
             $new_sql = $this->translateLimitOffsetToRowNumber($new_sql);
         }
         // SQL Server does not like to give unicode results back to PHP without some coersion
         if ($this->database->getType() == 'mssql') {
             $new_sql = $this->fixMSSQLNationalColumns($new_sql);
         }
         if ($this->database->getType() == 'oracle') {
             // Oracle has this nasty habit of silently translating empty strings to null
             $new_sql = $this->fixOracleEmptyStrings($new_sql);
             $new_sql = $this->uppercaseIdentifiers($new_sql);
         }
         if ($this->database->getType() == 'db2') {
             $new_sql = $this->uppercaseIdentifiers($new_sql);
         }
         $extra_statements = array();
         if (preg_match('#^\\s*(CREATE|DROP|ALTER|COMMENT)\\b#i', $new_sql)) {
             if (!isset($this->schema_translation)) {
                 $this->schema_translation = new fSQLSchemaTranslation($this->database);
             }
             list($new_sql, $extra_statements) = $this->schema_translation->translate($new_sql, $rollback_statements);
         }
         if ($sql != $new_sql || $extra_statements) {
             fCore::debug(self::compose("Original SQL:%s", "\n" . $sql), $this->debug);
             $translated_sql = $new_sql;
             if ($extra_statements) {
                 $translated_sql .= '; ' . join('; ', $extra_statements);
             }
             fCore::debug(self::compose("Translated SQL:%s", "\n" . $translated_sql), $this->debug);
         }
         $output = array_merge($output, array($number . ':' . $sql => $new_sql), array_values($extra_statements));
     }
     return $output;
 }
예제 #9
0
function notify_multiple_users($user_from, $recipients, $subject, $body)
{
    $email = new fEmail();
    // This sets up fSMTP to connect to the gmail SMTP server
    // with a 5 second timeout. Gmail requires a secure connection.
    $smtp = new fSMTP(sys_var('smtp_server'), sys_var('smtp_port'), sys_var('require_ssl') === 'true' ? TRUE : FALSE, 5);
    if (sys_var('require_auth') === 'true') {
        $smtp->authenticate(sys_var('smtp_user'), sys_var('smtp_pass'));
    }
    // Add the recipients
    foreach ($recipients as $rec) {
        $email->addRecipient($rec['mail'], $rec['name']);
    }
    // Set who the email is from
    $email->setFromEmail($user_from->getEmail(), $user_from->getUsername());
    // Set the subject
    $email->setSubject($subject);
    // Set the body
    $email->setHTMLBody($body);
    $email->setBody($body);
    try {
        $message_id = $email->send($smtp);
    } catch (fConnectivityException $e) {
        fCore::debug($e, FALSE);
        fCore::debug("email send failed", FALSE);
        $e->printMessage();
        $e->printTrace();
    }
}
예제 #10
0
 /**
  * Resets the configuration of the class
  * 
  * @internal
  * 
  * @return void
  */
 public static function reset()
 {
     if (self::$handles_errors) {
         restore_error_handler();
     }
     if (self::$handles_exceptions) {
         restore_exception_handler();
     }
     if (is_array(self::$captured_errors)) {
         restore_error_handler();
     }
     self::$captured_error_regex = NULL;
     self::$captured_errors_previous_handler = NULL;
     self::$captured_error_types = NULL;
     self::$captured_errors = NULL;
     self::$context_shown = FALSE;
     self::$debug = NULL;
     self::$debug_callback = NULL;
     self::$dynamic_constants = FALSE;
     self::$error_destination = 'html';
     self::$error_message_queue = array();
     self::$exception_destination = 'html';
     self::$exception_handler_callback = NULL;
     self::$exception_handler_parameters = array();
     self::$exception_message = NULL;
     self::$handles_errors = FALSE;
     self::$handles_exceptions = FALSE;
     self::$show_context = TRUE;
 }
예제 #11
0
파일: Check.php 프로젝트: nagyist/Tattle
 /**
  * Creates all Check related URLs for the site
  *
  * @param  string $type  The type of URL to make: 'list', 'add', 'edit', 'delete'
  * @param  Meetup $obj   The Check object for the edit and delete URL types
  * @return string  The URL requested
  */
 public static function setResultsLevel($value, $obj = NULL)
 {
     if ($obj->getOverUnder() == 0) {
         if ($value >= $obj->getError()) {
             $state = 1;
         } elseif ($value >= $obj->getWarn()) {
             $state = 2;
         } else {
             //echo 'all good ' . " $value <br />";
             $state = 0;
         }
         return $state;
     }
     if ($obj->getOverUnder() == 1) {
         if ($value > $obj->getWarn()) {
             $state = 0;
         } elseif ($value > $obj->getError()) {
             $state = 2;
         } else {
             fCore::debug('error state' . " {$value} compared to " . $obj->getError() . "<br />", FALSE);
             $state = 1;
         }
         return $state;
     }
 }
예제 #12
0
파일: fCore.php 프로젝트: philip/flourish
 /**
  * Resets the configuration of the class
  * 
  * @internal
  * 
  * @return void
  */
 public static function reset()
 {
     restore_error_handler();
     restore_exception_handler();
     self::$context_shown = FALSE;
     self::$debug = NULL;
     self::$debug_callback = NULL;
     self::$dynamic_constants = FALSE;
     self::$error_destination = 'html';
     self::$error_message_queue = array();
     self::$exception_destination = 'html';
     self::$exception_handler_callback = NULL;
     self::$exception_handler_parameters = array();
     self::$exception_message = NULL;
     self::$handles_errors = FALSE;
     self::$show_context = TRUE;
 }
예제 #13
0
파일: fSMTP.php 프로젝트: mrjwc/printmaster
 /**
  * Sends raw text/commands to the SMTP server
  * 
  * @param  string         $data    The data or commands to send
  * @param  integer|string $expect  The expected number of lines of response or a regex of the last line
  * @return array  The response from the server
  */
 private function write($data, $expect)
 {
     if (!$this->connection) {
         throw new fProgrammerException('Unable to send data since the connection has already been closed');
     }
     if (substr($data, -2) != "\r\n") {
         $data .= "\r\n";
     }
     if (fCore::getDebug($this->debug)) {
         fCore::debug("Sending:\n" . trim($data), $this->debug);
     }
     $res = fwrite($this->connection, $data);
     if ($res === FALSE || $res === 0) {
         throw new fConnectivityException('Unable to write data to SMTP server %1$s on port %2$s', $this->host, $this->port);
     }
     $response = $this->read($expect);
     return $response;
 }
예제 #14
0
 /**
  * Translates Flourish SQL into the dialect for the current database
  * 
  * @internal
  * 
  * @param  array $statements  The SQL statements to translate
  * @param  array $strings     The strings to interpolate back into the SQL statements
  * @return array  The translated SQL statements all ready for execution. Statements that have been translated will have string key of the original SQL, all other will have a numeric key.
  */
 public function translate($statements, $strings)
 {
     $output = array();
     foreach ($statements as $number => $sql) {
         // These fixes don't need to know about strings
         $new_sql = $this->translateBasicSyntax($sql);
         if ($this->database->getType() == 'mssql' || $this->database->getType() == 'oracle') {
             $new_sql = $this->translateLimitOffsetToRowNumber($new_sql);
         }
         // SQL Server does not like to give unicode results back to PHP without some coersion
         if ($this->database->getType() == 'mssql') {
             $new_sql = $this->fixMSSQLNationalColumns($new_sql);
         }
         // Oracle has this nasty habit of silently translating empty strings to null
         if ($this->database->getType() == 'oracle') {
             $new_sql = $this->fixOracleEmptyStrings($new_sql, $strings[$number]);
         }
         // Unescape literal semicolons in the queries
         $sql = preg_replace('#(?<!\\\\)\\\\;#', ';', $sql);
         $new_sql = preg_replace('#(?<!\\\\)\\\\;#', ';', $new_sql);
         $extra_statements = array();
         $new_sql = $this->translateCreateTableStatements($new_sql, $extra_statements);
         // Put the strings back into the SQL
         foreach ($strings[$number] as $index => $string) {
             $string = strtr($string, array('\\' => '\\\\', '$' => '\\$'));
             $sql = preg_replace('#:string_' . $index . '\\b#', $string, $sql, 1);
             $new_sql = preg_replace('#:string_' . $index . '\\b#', $string, $new_sql, 1);
         }
         $new_sql = $this->translateDateFunctions($new_sql);
         if ($sql != $new_sql || $extra_statements) {
             fCore::debug(self::compose("Original SQL:%s", "\n" . $sql), $this->debug);
             $translated_sql = $new_sql;
             if ($extra_statements) {
                 $translated_sql .= '; ' . join('; ', $extra_statements);
             }
             fCore::debug(self::compose("Translated SQL:%s", "\n" . $translated_sql), $this->debug);
         }
         $output = array_merge($output, array($sql => $new_sql), $extra_statements);
     }
     return $output;
 }
예제 #15
0
            fCore::debug("next check is lt then now\n", FALSE);
        } else {
            fCore::debug("not less then now\n", FALSE);
        }
        // If It's been more then the Repeat Delay or the Status has changed
        if ($next_check->lt($end) || $check->getLastCheckStatus() != $result) {
            fCore::debug("Send Notification \n", FALSE);
            fCore::debug("State :" . $result . ":\n", FALSE);
            $check_result = new CheckResult();
            $check_result->setCheckId($check->getCheckId());
            $check_result->setStatus($result);
            $check_result->setValue($check_value);
            $check_result->setState(0);
            $check->setLastCheckStatus($result);
            $check->setLastCheckValue($check_value);
            $check->setLastCheckTime($end);
            $check_result->store();
            $check->store();
            $subscriptions = Subscription::findAll($check->getCheckId());
            foreach ($subscriptions as $subscription) {
                $notify_function = $subscription->getMethod() . '_notify';
                if (function_exists($notify_function)) {
                    $notify_result = $notify_function($check, $check_result, $subscription);
                }
            }
        } else {
            fCore::debug("Skip Notification \n", FALSE);
        }
    }
    fCore::debug("check done moving to next \n\n", FALSE);
}
예제 #16
0
 /**
  * Runs a single statement and times it, removes any old unbuffered queries before starting
  * 
  * @param  string|fStatement $statement    The SQL statement or prepared statement to execute
  * @param  string            $result_type  The type of result object to return, fResult or fUnbufferedResult
  * @return fResult|fUnbufferedResult  The result for the query
  */
 private function run($statement, $result_type = NULL, $params = array())
 {
     if ($this->unbuffered_result) {
         $this->unbuffered_result->__destruct();
         $this->unbuffered_result = NULL;
     }
     $start_time = microtime(TRUE);
     if (is_object($statement)) {
         $sql = $statement->getSQL();
     } else {
         $sql = $statement;
     }
     if (!($result = $this->handleTransactionQueries($sql, $result_type))) {
         if ($result_type) {
             $result = new $result_type($this, $this->type == 'mssql' ? $this->schema_info['character_set'] : NULL);
             $result->setSQL($sql);
             if ($result_type == 'fResult') {
                 $this->performQuery($statement, $result, $params);
             } else {
                 $this->performUnbufferedQuery($statement, $result, $params);
             }
         } else {
             $this->perform($statement, $params);
         }
     }
     // Write some debugging info
     $query_time = microtime(TRUE) - $start_time;
     $this->query_time += $query_time;
     if (fCore::getDebug($this->debug)) {
         fCore::debug(self::compose('Query time was %1$s seconds for:%2$s', $query_time, "\n" . $sql), $this->debug);
     }
     if ($this->hook_callbacks['run']) {
         foreach ($this->hook_callbacks['run'] as $callback) {
             $callback_params = array($this, is_object($statement) ? array($statement, $params) : $sql, $query_time, $result);
             call_user_func_array($callback, $callback_params);
         }
     }
     if ($result_type) {
         return $result;
     }
 }
예제 #17
0
function validate_results($test_value, $alert_config) {
  if ($test_value >= $alert_config->error) { 
    fCore::debug('error state' . " $test_value\n",FALSE); 
    $state = 1;
  } elseif ($test_value >= $alert_config->warn) { 
    fCore::debug('warn state' . " $test_value\n",FALSE); 
    $state = 2;
  } else { 
    fCore::debug('all good ' . " $test_value\n",FALSE);
    $state = 0;
  }
  return $state;
}