From 64168cd4a087a03d64e62efa30a449ae43dd8b9f Mon Sep 17 00:00:00 2001 From: Dan Rowe Date: Fri, 4 Nov 2011 23:23:05 -0400 Subject: [PATCH] variable/include path cleanup. added .gitignore. allow config.overide.php. --- .gitignore | 3 + README.md | 16 +++++ ajax/alerts_json.php | 2 +- ajax/autocomplete.php | 27 +++++--- ajax/get_rawdata.php | 18 +++-- check.php | 6 +- dashboard.php | 9 +-- graphite_tattle_schema_alpha.sql | 1 + graphs.php | 11 ++- inc/classes/Check.php | 71 ++++++++++++------- inc/classes/Graph.php | 2 - inc/config.php | 115 +++++++++++++++++++++---------- inc/functions.php | 20 ++---- inc/includes.php | 6 +- inc/init.php | 29 ++++---- inc/views/header.php | 8 +-- inc/views/result.php | 53 -------------- index.php | 4 +- lines.php | 13 ++-- login.php | 59 ++++++---------- processor.php | 2 +- result.php | 8 +-- subscription.php | 2 +- user.php | 6 +- 24 files changed, 244 insertions(+), 247 deletions(-) create mode 100644 .gitignore delete mode 100644 inc/views/result.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..51f19a7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +inc/config.override.php +*~ +js_cache diff --git a/README.md b/README.md index cf1a707..b176760 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,22 @@ Installation and Configuration * Create a session storage folder for flourishlib +* Create JS/CSS minification directory and allow Apache to write to it. By default this is + /js_cache e.g. + + install -o www-data /var/www/js_cache/images + +* Create a file called inc/config.override.php so that upgrades don't blow away your config + + Your config.override might look something like this: +-------------------------- + scanRecursive($path. '*'); -$return_arr = array(); -foreach ($directories as $directory) { - $return_arr[] = array('value' => str_replace('.wsp','',str_replace('/','.',str_replace(WHISPER_DIR,'',$directory->getPath())))); +if ($GLOBALS['PRIMARY_SOURCE'] == 'GANGLIA') { + if ($GLOBALS['GANGLIA_URL'] != '') { + $json = file_get_contents($GLOBALS['GANGLIA_URL'] . '/tattle_autocomplete.php?term=' . $term); + print $json; + } +} else { + $dir = new fDirectory($GLOBALS['WHISPER_DIR']); + $path = str_replace('.', '/' ,fRequest::get('term','string')); + $directories = $dir->scanRecursive($path. '*'); + $return_arr = array(); + foreach ($directories as $directory) { + $return_arr[] = array('value' => str_replace('.wsp','',str_replace('/','.',str_replace($GLOBALS['WHISPER_DIR'],'',$directory->getPath())))); + } + print json_encode($return_arr); } - -/* Toss back results as json encoded array. */ -echo json_encode($return_arr); diff --git a/ajax/get_rawdata.php b/ajax/get_rawdata.php index 1f9db76..33c0e4a 100644 --- a/ajax/get_rawdata.php +++ b/ajax/get_rawdata.php @@ -1,5 +1,5 @@ prepareTarget() . - '&target=keepLastValue(threshold(' . $check->prepareWarn() .'))' ; -// '&target=threshold(' . $check->prepareError() . ')'; + +if ( $GLOBALS['PRIMARY_SOURCE'] == "GANGLIA" ) { + $parts = explode("_|_", $check->prepareTarget()); + $url = $GLOBALS['GANGLIA_URL'] . "/graph.php?graphlot=1&cs=-1day&ce=now&c=" . + $parts[0] . "&h=" . $parts[1] . "&m=" . $parts[2]; +} else { + $url = $GLOBALS['GRAPHITE_URL'] . '/graphlot/rawdata?&from=-24hour&until=-0hour' . + '&target=' . $check->prepareTarget() . + '&target=keepLastValue(threshold(' . $check->prepareWarn() .'))' ; +} $contents = file_get_contents($url); -//$contents = file_get_contents(GRAPHITE_URL . '/graphlot/rawdata?&from=-24hour&until=-0hour&target=' . $check->prepareTarget() . '&target=' . $check->prepareWarn() . '&target=' . $check->prepareError()); print $contents; diff --git a/check.php b/check.php index f9c9ddc..d8f4d8b 100644 --- a/check.php +++ b/check.php @@ -1,14 +1,12 @@ 'Checks', 'url' => Check::makeUrl('list'), 'active'=> false); -$action = fRequest::getValid('action', - array('list', 'add', 'edit', 'delete') -); +$action = fRequest::getValid('action', array('list', 'add', 'edit', 'delete')); $sort = fCRUD::getSortColumn(array('name','target','warn','error','status','timestamp','count')); $sort_dir = fCRUD::getSortDirection('asc'); diff --git a/dashboard.php b/dashboard.php index a59a96e..38fd885 100644 --- a/dashboard.php +++ b/dashboard.php @@ -1,13 +1,11 @@ 'Dashboards', 'url' => Dashboard::makeUrl('list'),'active' => false); -$action = fRequest::getValid('action', - array('list', 'add', 'edit', 'delete', 'view') -); +$action = fRequest::getValid('action', array('list', 'add', 'edit', 'delete', 'view')); $full_screen = fRequest::get('full_screen','boolean',false); $dashboard_id = fRequest::get('dashboard_id','integer'); @@ -19,7 +17,7 @@ try { $dashboard = new Dashboard($dashboard_id); $graphs = $dashboard->buildGraphs(); - //$graphs = Graph::findAll($dashboard_id); + if (fRequest::isPost()) { $dashboard->populate(); fRequest::validateCSRFToken(fRequest::get('token')); @@ -28,7 +26,6 @@ fMessaging::create('affected', fURL::get(), $dashboard->getName()); fMessaging::create('success', fURL::get(), 'The Dashboard ' . $dashboard->getName(). ' was successfully updated'); - //fURL::redirect($manage_url); } } catch (fNotFoundException $e) { fMessaging::create('error', Dashboard::makeUrl('list'), diff --git a/graphite_tattle_schema_alpha.sql b/graphite_tattle_schema_alpha.sql index 921bd4a..8529fc1 100644 --- a/graphite_tattle_schema_alpha.sql +++ b/graphite_tattle_schema_alpha.sql @@ -12,6 +12,7 @@ CREATE TABLE `users` ( CREATE TABLE `settings` ( `setting_id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, + `friendly_name` varchar(200) NOT NULL, `value` varchar(500) NOT NULL, `plugin` varchar(200) NOT NULL, `type` varchar(100) NOT NULL DEFAULT 'string', diff --git a/graphs.php b/graphs.php index 17f9a41..4570d00 100644 --- a/graphs.php +++ b/graphs.php @@ -1,16 +1,14 @@ getName()); fMessaging::create('success', fURL::getWithQueryString(), 'The Graph ' . $graph->getName(). ' was successfully updated'); - //fURL::redirect($manage_url); } } catch (fNotFoundException $e) { fMessaging::create('error', $manage_url, diff --git a/inc/classes/Check.php b/inc/classes/Check.php index 6535b37..2ff05dc 100644 --- a/inc/classes/Check.php +++ b/inc/classes/Check.php @@ -81,7 +81,6 @@ static public function acknowledgeCheck($check=NULL,$result=NULL,$ackAll=false) $check_results = CheckResult::build($result->getResultId()); } foreach ($check_results as $check_result) { - fCore::expose($check_result); $check_result->setAcknowledged(1); $check_result->store(); } @@ -95,7 +94,17 @@ static public function acknowledgeCheck($check=NULL,$result=NULL,$ackAll=false) */ static public function getData($obj=NULL) { - $check_url = GRAPHITE_URL . '/render/?target=' . $obj->prepareTarget() . '&from='. $obj->prepareSample() . '&format=json'; + if ( $GLOBALS['PRIMARY_SOURCE'] == "GANGLIA" ) { + $check_url = $GLOBALS['GANGLIA_URL'] . '/graph.php/?' . + 'target=' . $obj->prepareTarget() . + '&cs='. $obj->prepareSample() . + '&ce=now&format=json'; + } else { + $check_url = $GLOBALS['GRAPHITE_URL'] . '/render/?' . + 'target=' . $obj->prepareTarget() . + '&from='. $obj->prepareSample() . + '&format=json'; + } $json_data = @file_get_contents($check_url); if ($json_data) { $data = json_decode($json_data); @@ -175,31 +184,47 @@ static public function showGraph($obj=NULL,$img=true,$sample=false,$width=false, } else { $link = 'prepareTarget()); + $link .= $GLOBALS['GANGLIA_URL'] . "/graph.php?json=1&ce=now&c=" . + $parts[0] . "&h=" . $parts[1] . "&m=" . $parts[2]; + + if ($sample !== False) { + $link .= '&cs=' . $sample; + } else { + $link .= '&cs=' . $obj->prepareSample(); + } + + } else { + + $link .= $GLOBALS['GRAPHITE_URL'] . '/render/?'; + $link .= 'target=legendValue(alias(' . $obj->prepareTarget() . '%2C%22Check : ' . $obj->prepareName() .'%22),%22last%22)'; + if ($sample !== False) { + $link .= '&from=' . $sample; + } else { + $link .= '&from=' . $obj->prepareSample(); + } + if ($width !== false) { + $link .= '&width=' .$width; + } else { + $link .= '&width=' .$GLOBALS['GRAPH_WIDTH']; + } + $link .= '&height=' .$GLOBALS['GRAPH_HEIGHT']; + $link .= '&target=color(alias(threshold('. $obj->getError() . ')%2C%22Error%20('. $obj->getError() . ')%22)%2C%22' . $GLOBALS['ERROR_COLOR'] . '%22)'; + $link .= '&target=color(alias(threshold('. $obj->getWarn() . ')%2C%22Warning%20('. $obj->getWarn() . ')%22)%2C%22' . $GLOBALS['WARN_COLOR'] . '%22)'; + if ($hideLegend !== false) { + $link .= '&hideLegend=true'; + } } - $link .= '&height=' .GRAPH_HEIGHT; - $link .= '&target=color(alias(threshold('. $obj->getError() . ')%2C%22Error%20('. $obj->getError() . ')%22)%2C%22' . ERROR_COLOR . '%22)'; - $link .= '&target=color(alias(threshold('. $obj->getWarn() . ')%2C%22Warning%20('. $obj->getWarn() . ')%22)%2C%22' . WARN_COLOR . '%22)'; - if ($hideLegend !== false) { - $link .= '&hideLegend=true'; - } + if ($img) { $link .= '" title="' . $obj->prepareName() . '" alt="' . $obj->prepareName(); $link .= '" />'; - } else { - $link .= '"> ' . $obj->prepareTarget() .''; - } + } else { + $link .= '"> ' . $obj->prepareTarget() .''; + } return $link; } diff --git a/inc/classes/Graph.php b/inc/classes/Graph.php index 79a24f9..c484a5f 100644 --- a/inc/classes/Graph.php +++ b/inc/classes/Graph.php @@ -41,8 +41,6 @@ static public function makeURL($type, $obj=NULL) static function drawGraph($obj=NULL,$parent=NULL) { - //fCore::expose($parent); - //fCore::expose($obj); $link = 'http://graph/render/?'; $lines = Line::findAll($obj->getGraphId()); foreach($lines as $line) { diff --git a/inc/config.php b/inc/config.php index 3fea16c..34af03f 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1,35 +1,84 @@ Tattle Error
" . - "Flourishlib not found : expected at : " . $root_path . FLOURISHLIB_PATH . "
" . - "Can be changed in inc/config.php : FLOURISHLIB_PATH"; + +try { + //Set DB connection (using flourish it isn't actually connected to until the first use) + $mysql_db = new fDatabase('mysql', $GLOBALS['DATABASE_NAME'],$GLOBALS['DATABASE_USER'], $GLOBALS['DATABASE_PASS']); + // Please note that calling this method is not required, and simply + // causes an exception to be thrown if the connection can not be made + $mysql_db->connect(); +} catch (fAuthorizationException $e) { + $config_error = "DB error : " . $e->getMessage(); $config_exit = true; } -if (!file_exists($root_path . BOOTSTRAP_PATH . 'bootstrap.css')) { - $config_error .= "
Tattle Error
" . - "Bootstrap library not found : expected at : " . $root_path . BOOTSTRAP_PATH . "
" . - "Can be changed in inc/config.php : BOOTSTRAP_PATH"; - $config_exit = true; +//Connect the db to the ORM functions +fORMDatabase::attach($mysql_db); + + + +if (!is_dir(JS_CACHE)) { + $config_error .="
Tattle Error
" . + "Can't write to the js cache folder : " . JS_CACHE; +} + +if (!is_dir($GLOBALS['SESSION_FILES']) || !is_writable($GLOBALS['SESSION_FILES'])){ + $config_error .="
Tattle Error
" . + "Flourishlib Session path is not write-able. Path at : " . $GLOBALS['SESSION_FILES']; + $config_error = true; } if ($config_exit) { @@ -37,7 +86,7 @@ exit; } -define('VIEW_PATH', $root_path . '/views/'); + $status_array = array('0' => 'OK', '1' => 'Error', '2' => 'Warning'); $visibility_array = array('0' => 'Public', '1' => 'Private'); $over_under_array = array('0' => 'Over', '1' => 'Under'); @@ -58,15 +107,5 @@ ) ); // This prevents cross-site session transfer -fSession::setPath(SESSION_FILES_PATH); +fSession::setPath($GLOBALS['SESSION_FILES']); -$plugin_settings = array(); -foreach (glob("plugins/*_plugin.php") as $plugin) { - include_once($plugin); - $plugin_name = str_replace(array('plugins/', '_plugin.php'), '', $plugin); - $plugin_config = $plugin_name . '_config'; - if (function_exists($plugin_config)) { - $plugin_settings[$plugin_name] = $plugin_config(); - $send_methods[$plugin_name] = $plugin_settings[$plugin_name]['name']; - } -} diff --git a/inc/functions.php b/inc/functions.php index 5519f14..9e885b9 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1,4 +1,5 @@ '; if ($nid > 0) { @@ -75,7 +75,6 @@ function edit_alert($nid=0) { } function save_alert($post_data,$mode) { - //print "Mode in function : $mode"; global $dblink, $username; if (count($post_data) > 8) { $title = validate_element($post_data,'title'); @@ -93,10 +92,8 @@ function save_alert($post_data,$mode) { } else { $sql = "INSERT INTO checks (title,owner,target,warn,error,sample,baseline,over_under,visibility) VALUES ('" . $title . "','" . $owner . "','" . $target . "','" . $warn . "','" . $error . "','" . $sample . "','" . $baseline . "','" . $over_under. "','" . $visibility ."');"; } - //print $sql; $results = mysql_query($sql,$dblink); if (!$results) { - //print 'Results Error : ' . mysql_error(). "\n"; } else { print 'Alert Updated'; } @@ -137,7 +134,6 @@ function generate_comparison_value($data, $alert_config){ if ($alert_config->baseline == 'average') { $compare_value = subarray_average($data[0]->datapoints); } elseif ($alert_config->baseline == 'median') { - //print_r($data[0]->datapoints); $compare_value = subarray_median($data[0]->datapoints); } return $compare_value; @@ -158,7 +154,6 @@ function validate_results($test_value, $alert_config) { } function display_alert_row($alert_config) { - //print_r($alert_config); $return = '' . make_graphite_link($alert_config, true) . ''; $return .= '' . $alert_config['owner'] . ''; $return .= '' . $alert_config['target'] . ''; @@ -174,7 +169,7 @@ function display_alert_row($alert_config) { } function action_buttons($alert_config) { - global $username; + global $username; $results = ''; if ($username == $alert_config['owner']) { $results .= 'Edit Alert | '; @@ -185,13 +180,6 @@ function action_buttons($alert_config) { $results .= 'Subscribe | '; } - //need to figure this out differently based on db; - //if (in_object_key($username,$alert_config->subscribers)){ -// $results .= 'Edit Subscription : '; -// } else { - //$results .= 'Subscribe : '; - //} - return $results; } @@ -236,7 +224,7 @@ function display_subscribers_count($nid){ } function make_graphite_link($alert_config, $make_href = true, $href_title = false) { - $link = GRAPHITE_URL . '?target=' . $alert_config['target'] . '&from=' . $alert_config['sample']; + $link = $GLOBALS['GRAPHITE_URL'] . '?target=' . $alert_config['target'] . '&from=' . $alert_config['sample']; if ($make_href) { if ($href_title === false) { $title = $alert_config['title']; @@ -249,7 +237,7 @@ function make_graphite_link($alert_config, $make_href = true, $href_title = fals } function get_check_data($alert_config){ - $json_data = file_get_contents(GRAPHITE_URL . '?target=' . $alert_config->target . '&from=-5minutes&format=json'); + $json_data = file_get_contents( $GLOBALS['GRAPHITE_URL'] . '?target=' . $alert_config->target . '&from=-5minutes&format=json'); $data = json_decode($json_data); return $data; } diff --git a/inc/includes.php b/inc/includes.php index 3a7bb83..8ff00a6 100644 --- a/inc/includes.php +++ b/inc/includes.php @@ -1,7 +1,7 @@ enableMinification('development', dirname(__FILE__) . '/../js_cache/',dirname(__FILE__) . '/..'); +if (!is_dir(JS_CACHE) || !is_writable(JS_CACHE)){ + $warning_message .= "JS Caching disabled due to js folder permissions"; +} else { + $tmpl->enableMinification('development', JS_CACHE, TATTLE_ROOT); +} $tmpl->add('css','/bootstrap/bootstrap.min.css'); $tmpl->add('css','/assets/css/jquery-ui.css'); @@ -27,11 +34,5 @@ $tmpl->set('header', 'header.php'); $tmpl->set('footer', 'footer.php'); -//Set DB connection (using flourish it isn't actually connected to until the first use) -$mysql_db = new fDatabase('mysql', $database_name, $database_user, $database_password); - -//Connect the db to the ORM functions -fORMDatabase::attach($mysql_db); - //Start the Flourish Session fSession::open(); diff --git a/inc/views/header.php b/inc/views/header.php index 232efac..022aa6b 100644 --- a/inc/views/header.php +++ b/inc/views/header.php @@ -15,10 +15,10 @@ $this->place('css'); $this->place('js'); if ($this->get('graphlot')) { ?> - - - - + + + +