コード例 #1
0
 /**
  * validation method - may be overriden by sub-classes, but parent method 
  * should still be invoked. returns TRUE if db options are valid, FALSE 
  * otherwise
  * @return boolean
  */
 protected function validate()
 {
     if ($valid = parent::validate()) {
         if (!isset($this->options['db_name'])) {
             $valid = FALSE;
             print_msg('--db_name argument is required for --db bigquery', isset($this->options['verbose']), __FILE__, __LINE__, TRUE);
         } else {
             if ($this->bq() !== NULL) {
                 $valid = TRUE;
                 print_msg('BigQuery connection successful', isset($this->options['verbose']), __FILE__, __LINE__);
             } else {
                 print_msg('BigQuery connection failed', isset($this->options['verbose']), __FILE__, __LINE__, TRUE);
             }
         }
     }
     return $valid;
 }
コード例 #2
0
 /**
  * validation method - may be overriden by sub-classes, but parent method 
  * should still be invoked. returns TRUE if db options are valid, FALSE 
  * otherwise
  * @return boolean
  */
 protected function validate()
 {
     if ($valid = parent::validate()) {
         $table = 'test_' . $this->getTableName(rand());
         if ($this->mysql(sprintf('CREATE TABLE %s (id int)%s', $table, isset($this->options['db_mysql_engine']) ? ' ENGINE=' . $this->options['db_mysql_engine'] : '')) !== NULL) {
             // try to load some data into the table
             $fp = fopen($tmp = '/tmp/' . $table, 'w');
             fwrite($fp, rand() . "\n" . rand());
             fclose($fp);
             $query = sprintf("LOAD DATA LOCAL INFILE '%s' INTO TABLE %s", $tmp, $table);
             $imported = $this->mysql($query);
             unlink($tmp);
             $this->mysql('drop table ' . $table);
             $dropped = $this->mysql('desc ' . $table);
             if ($dropped !== NULL) {
                 print_msg(sprintf('Unable to drop test table %s - check that user has DROP TABLE permissions', $table), isset($this->options['verbose']), __FILE__, __LINE__, TRUE);
                 $valid = FALSE;
             } else {
                 if ($imported !== NULL) {
                     print_msg(sprintf('Validated MySQL connection by creating and importing data to a temporary table %s - table has been removed', $table), isset($this->options['verbose']), __FILE__, __LINE__);
                 } else {
                     $valid = FALSE;
                     print_msg(sprintf('MySQL connection successful, but unable to import data using LOAD DATA LOCAL INFILE. Check these permissions for this user'), isset($this->options['verbose']), __FILE__, __LINE__, TRUE);
                 }
             }
         } else {
             $valid = FALSE;
             print_msg(sprintf('MySQL connection failed - %s', $this->mysql() !== NULL ? 'user cannot create tables' : 'unable to connect to server'), isset($this->options['verbose']), __FILE__, __LINE__, TRUE);
         }
     }
     return $valid;
 }
コード例 #3
0
 /**
  * validation method - may be overriden by sub-classes, but parent method 
  * should still be invoked. returns TRUE if db options are valid, FALSE 
  * otherwise
  * @return boolean
  */
 protected function validate()
 {
     if (!isset($this->valid) && parent::validate()) {
         $this->valid = TRUE;
         $validate = array('db_librato_color' => array('color' => TRUE), 'db_librato_display_max' => array('min' => 0), 'db_librato_display_min' => array('min' => 0), 'db_librato_period' => array('min' => 0), 'db_librato_type' => array('option' => array('counter', 'gauge')), 'db_user' => array('required' => TRUE), 'db_pswd' => array('required' => TRUE));
         if ($validated = validate_options($this->options, $validate)) {
             $this->valid = FALSE;
             foreach ($validated as $param => $err) {
                 print_msg(sprintf('--%s is not valid: %s', $param, $err), isset($this->options['verbose']), __FILE__, __LINE__, TRUE);
             }
         } else {
             $valueCol = 'db_librato_value';
             if (!isset($this->options['db_librato_value'])) {
                 $valueCol = 'db_librato_count';
                 if (!isset($this->options['db_librato_count']) || !isset($this->options['db_librato_sum'])) {
                     $this->valid = FALSE;
                     print_msg(sprintf('If --db_librato_value is not set, both --db_librato_count and --db_librato_sum MUST be specified'), isset($this->options['verbose']), __FILE__, __LINE__, TRUE);
                 } else {
                     if (count($this->options['db_librato_count']) != count($this->options['db_librato_sum'])) {
                         $this->valid = FALSE;
                         print_msg(sprintf('--db_librato_count and --db_librato_sum must be repeated the same number of times'), isset($this->options['verbose']), __FILE__, __LINE__, TRUE);
                     } else {
                         if (isset($this->options['db_librato_name']) && count($this->options['db_librato_name']) != count($this->options['db_librato_count'])) {
                             $this->valid = FALSE;
                             print_msg(sprintf('--db_librato_name and --db_librato_count must be repeated the same number of times'), isset($this->options['verbose']), __FILE__, __LINE__, TRUE);
                         }
                     }
                 }
             } else {
                 if (isset($this->options['db_librato_name']) && count($this->options['db_librato_name']) != count($this->options['db_librato_value'])) {
                     $this->valid = FALSE;
                     print_msg(sprintf('--db_librato_name and --db_librato_value must be repeated the same number of times'), isset($this->options['verbose']), __FILE__, __LINE__, TRUE);
                 } else {
                     if (isset($this->options['db_librato_count']) || isset($this->options['db_librato_sum']) || isset($this->options['db_librato_max']) || isset($this->options['db_librato_min']) || isset($this->options['db_librato_sum_squares'])) {
                         $this->valid = FALSE;
                         print_msg(sprintf('--db_librato_value cannot be set with --db_librato_count, --db_librato_sum, --db_librato_max, --db_librato_min or --db_librato_sum_squares because these parameters are mutually exclusive'), isset($this->options['verbose']), __FILE__, __LINE__, TRUE);
                     }
                 }
             }
             if ($this->valid) {
                 foreach (array('db_librato_aggregate', 'db_librato_color', 'db_librato_count', 'db_librato_description', 'db_librato_display_max', 'db_librato_display_min', 'db_librato_display_name', 'db_librato_display_units_long', 'db_librato_display_units_short', 'db_librato_display_stacked', 'db_librato_display_transform', 'db_librato_max', 'db_librato_min', 'db_librato_measure_time', 'db_librato_period', 'db_librato_source', 'db_librato_sum', 'db_librato_summarize_function', 'db_librato_sum_squares', 'db_librato_type') as $param) {
                     if (isset($this->options[$param]) && count($this->options[$param]) != count($this->options[$valueCol]) && count($this->options[$param]) != 1) {
                         $this->valid = FALSE;
                         print_msg(sprintf('--%s can only be set once or %d times (once for each --%s)', $param, count($this->options[$valueCol]), $valueCol), isset($this->options['verbose']), __FILE__, __LINE__, TRUE);
                     }
                 }
             }
         }
         if ($this->valid) {
             // validate credentials using GET request
             $curl = ch_curl(self::LIBRATO_METRICS_API_URL, 'GET', NULL, NULL, sprintf('%s:%s', $this->options['db_user'], $this->options['db_pswd']), '200-299', TRUE);
             $this->valid = ($response = json_decode($curl, TRUE)) ? TRUE : FALSE;
             if ($curl === NULL) {
                 print_msg(sprintf('Librato API GET request to %s failed', self::LIBRATO_METRICS_API_URL), isset($this->options['verbose']), __FILE__, __LINE__, TRUE);
             } else {
                 if ($curl === FALSE) {
                     print_msg(sprintf('Librato API GET request to %s resulted in non 200 response code - API credentials may be invalid', self::LIBRATO_METRICS_API_URL), isset($this->options['verbose']), __FILE__, __LINE__, TRUE);
                 } else {
                     if ($curl && !$response) {
                         print_msg(sprintf('Librato API GET request to %s successful, but body did not contain valid JSON', self::LIBRATO_METRICS_API_URL), isset($this->options['verbose']), __FILE__, __LINE__, TRUE);
                     } else {
                         print_msg(sprintf('Librato API GET request to %s successful. There are %d existing metrics', self::LIBRATO_METRICS_API_URL, count($response['metrics'])), isset($this->options['verbose']), __FILE__, __LINE__);
                     }
                 }
             }
         }
     }
     return $this->valid;
 }
コード例 #4
0
 /**
  * validation method - may be overriden by sub-classes, but parent method 
  * should still be invoked. returns TRUE if db options are valid, FALSE 
  * otherwise
  * @return boolean
  */
 protected function validate()
 {
     if ($valid = parent::validate()) {
         if (isset($this->options['db_host'])) {
             if ($valid = ch_curl($this->getUrl(), 'HEAD', $this->getHeaders(), NULL, $this->getAuth())) {
                 print_msg('Successfully validated callback using HEAD request', isset($this->options['verbose']), __FILE__, __LINE__);
             } else {
                 print_msg('Unable to validate callback using HEAD request', isset($this->options['verbose']), __FILE__, __LINE__, TRUE);
             }
         } else {
             $valid = FALSE;
             print_msg('--db_host argument is required for --db callback', isset($this->options['verbose']), __FILE__, __LINE__, TRUE);
         }
     }
     return $valid;
 }
コード例 #5
0
ファイル: save.php プロジェクト: samuel1978/block-storage
require_once dirname(__FILE__) . '/BlockStorageTest.php';
require_once dirname(__FILE__) . '/save/BenchmarkDb.php';
$status = 1;
$args = parse_args(array('iteration:', 'nosave_fio', 'nostore_json', 'nostore_pdf', 'nostore_rrd', 'nostore_zip', 'v' => 'verbose'));
// get result directories => each directory stores 1 iteration of results
$dirs = array();
$dir = count($argv) > 1 && is_dir($argv[count($argv) - 1]) ? $argv[count($argv) - 1] : trim(shell_exec('pwd'));
if (is_dir(sprintf('%s/1', $dir))) {
    $i = 1;
    while (is_dir($sdir = sprintf('%s/%d', $dir, $i++))) {
        $dirs[] = $sdir;
    }
} else {
    $dirs[] = $dir;
}
if ($db =& BenchmarkDb::getDb()) {
    $db->tablePrefix = 'block_storage_';
    // get results from each directory
    foreach ($dirs as $i => $dir) {
        $iteration = isset($args['iteration']) && preg_match('/([0-9]+)/', $args['iteration'], $m) ? $m[1] * 1 : $i + 1;
        print_msg(sprintf('Saving results in directory %s', $dir), isset($args['verbose']), __FILE__, __LINE__);
        // save report.pdf and report.zip
        foreach (array('nostore_pdf' => 'report.pdf', 'nostore_zip' => 'report.zip') as $arg => $file) {
            $file = sprintf('%s/%s', $dir, $file);
            if (!isset($args[$arg]) && file_exists($file)) {
                $pieces = explode('.', $file);
                $col = sprintf('report_%s', $pieces[count($pieces) - 1]);
                $saved = $db->saveArtifact($file, $col);
                if ($saved) {
                    print_msg(sprintf('Saved %s successfully', basename($file)), isset($args['verbose']), __FILE__, __LINE__);
                } else {
コード例 #6
0
ファイル: NetworkTest.php プロジェクト: dynamicdeploy/network
 /**
  * returns test results - an array of hashes each containing the results from
  * 1 test
  * @return array
  */
 public function getResults()
 {
     $results = NULL;
     require_once sprintf('%s/benchmark/save/BenchmarkDb.php', dirname(__FILE__));
     if ($db =& BenchmarkDb::getDb()) {
         $this->getRunOptions();
         if ($results = isset($this->options['results']) ? $this->options['results'] : NULL) {
             $schema = $db->getSchema('network');
             foreach (array_keys($this->options) as $key) {
                 if (isset($schema[$key]) && preg_match('/^meta/', $key)) {
                     foreach (array_keys($results) as $i) {
                         if (!isset($results[$i][$key])) {
                             $results[$i][$key] = trim(is_array($this->options[$key]) ? implode(' ', $this->options[$key]) : $this->options[$key]);
                             if (!$results[$i][$key]) {
                                 unset($results[$i][$key]);
                             }
                         } else {
                             if ($results[$i][$key] === FALSE) {
                                 unset($results[$i][$key]);
                             }
                         }
                     }
                 }
             }
         }
     }
     return $results;
 }
コード例 #7
0
 /**
  * validation method - may be overriden by sub-classes, but parent method 
  * should still be invoked. returns TRUE if db options are valid, FALSE 
  * otherwise
  * @return boolean
  */
 protected function validate()
 {
     if ($valid = parent::validate()) {
         $table = 'test_' . $this->getTableName(rand());
         if ($this->psql('create table ' . $table . ' (id int)') !== NULL) {
             // try to load some data into the table
             $fp = fopen($tmp = '/tmp/' . $table, 'w');
             fwrite($fp, rand() . "\n" . rand());
             fclose($fp);
             $query = sprintf("\\COPY %s FROM '%s' CSV", $table, $tmp);
             $imported = $this->psql($query);
             unlink($tmp);
             $this->psql('drop table ' . $table);
             $dropped = $this->psql('\\d+ ' . $table);
             if ($dropped !== NULL) {
                 print_msg(sprintf('Unable to drop test table %s - check that user has DROP TABLE permissions', $table), isset($this->options['verbose']), __FILE__, __LINE__, TRUE);
                 $valid = FALSE;
             } else {
                 if ($imported !== NULL) {
                     print_msg(sprintf('Validated PostgreSQL connection by creating and importing data to a temporary table %s - table has been removed', $table), isset($this->options['verbose']), __FILE__, __LINE__);
                 } else {
                     $valid = FALSE;
                     print_msg(sprintf('PostgreSQL connection successful, but unable to import data using COPY. Check these permissions for this user'), isset($this->options['verbose']), __FILE__, __LINE__, TRUE);
                 }
             }
         } else {
             $valid = FALSE;
             print_msg(sprintf('PostgreSQL connection failed - %s', $this->psql() !== NULL ? 'user cannot create tables' : 'unable to connect to server'), isset($this->options['verbose']), __FILE__, __LINE__, TRUE);
         }
     }
     return $valid;
 }