diff --git a/controllers/CoreController.class.php b/controllers/CoreController.class.php index 944e059..7955805 100644 --- a/controllers/CoreController.class.php +++ b/controllers/CoreController.class.php @@ -84,5 +84,20 @@ public function getheader() $this->sendResponse('site_header', $viewData); } + /** + * search - Search Saigon Data + * + * @access public + * @return void + */ + public function search() + { + $viewData = new ViewData(); + $viewData->search = trim($this->getParam('search')); + $viewData->deployment = $this->getParam('deployment'); + $viewData->searchResults = SaigonSearch::search($viewData->deployment, $viewData->search); + $this->sendResponse('search', $viewData); + } + } diff --git a/include/SaigonSearch.class.php b/include/SaigonSearch.class.php new file mode 100644 index 0000000..4fee1d0 --- /dev/null +++ b/include/SaigonSearch.class.php @@ -0,0 +1,219 @@ +checkAuth($deployment) === true) { + array_push($viewDeployments, $deployment); + } + } + } elseif (in_array($deployment, $deployments)) { + if ($authmodule->checkAuth($deployment) === true) { + array_push($viewDeployments, $deployment); + } + } + asort($viewDeployments); + return $viewDeployments; + + } + + /* + * searchDeployment - search the component keys of a deployment + */ + private static function searchDeployment($deployment, $search) { + $results = array(); + $match = false; + + // Get the deployment version + $results['version'] = RevDeploy::getDeploymentRev($deployment); + + // See if deployment name matches + if (preg_match("/$search/", $deployment)) { + $results['deployment_name'] = $deployment; + $match = true; + } + + // Get the key hash + list($dKey) = array_shift(NagRedis::keys(md5('deployment:'.$deployment), false)); + $results['deployment_hash'] = $dKey; + + // Look through the deployment hash + list($match_deployment_info, $match_flag) = self::searchHash($dKey, $search); + if ($match_flag) { + $results['deployment_info'] = $match_deployment_info; + $match = true; + } + + // Other non-versioned keys + $nvKeys = array_shift(NagRedis::keys(md5('deployment:'.$deployment).":hostsearch*", true)); + sort($nvKeys); + foreach ($nvKeys as $nvKey) { + if (preg_match("/$search/", $nvKey)) { + if (isset($results['nonversioned']['key_name'])) { + array_push($results['nonversioned']['key_name'], $nvKey); + } else { + $results['nonversioned']['key_name'] = array($nvKey); + } + $match = true; + } + list($match_nv_info, $match_flag) = self::searchRedisKey($nvKey, $search); + if ($match_flag) { + if (isset($results['nonversioned']['key_value'][$nvKey])) { + array_push($results['nonversioned']['key_value'][$nvKey], $match_nv_info); + } else { + $results['nonversioned']['key_value'][$nvKey] = $match_nv_info; + } + $match = true; + } + } + + // Other versioned keys + $vKeys = array_shift(NagRedis::keys(md5('deployment:'.$deployment).":".$results['version'].":*", true)); + sort($vKeys); + foreach ($vKeys as $vKey) { + // skip buildoutput key + if (preg_match('/buildoutput/', $vKey)) continue; + if (preg_match("/$search/", $vKey)) { + if (isset($results['versioned']['key_name'])) { + array_push($results['versioned']['key_name'], $vKey); + } else { + $results['versioned']['key_name'] = array($vKey); + } + $match = true; + } + list($match_v_info, $match_flag) = self::searchRedisKey($vKey, $search); + if ($match_flag) { + if (isset($results['versioned']['key_value'][$vKey])) { + array_push($results['versioned']['key_value'][$vKey], $match_v_info); + } else { + $results['versioned']['key_value'][$vKey] = $match_v_info; + } + $match = true; + } + } + + $results['match'] = $match; + return $results; + } + + /* + * searchHash - search a hash type key + */ + private static function searchHash ($hashKey, $search) { + $results = array(); + $match = false; + + //echo var_dump($hashKey,true); exit; + foreach (NagRedis::hKeys($hashKey) as $hashKeyKey) { + if (preg_match("/$search/", $hashKeyKey)) { + if (isset($results['key_name'])) { + array_push($results['key_name'], "$hashKeyKey"); + } else { + $results['key_name'] = array("$hashKeyKey"); + } + $match = true; + } + $keyValue = NagRedis::hget($hashKey, $hashKeyKey); + // decode base64 encoded key values + if ($hashKeyKey == 'command_line' || $hashKeyKey == 'cmd_line' || $hashKeyKey == 'location' || $hashKeyKey == 'file' || preg_match('/^USER|^ARG/', $hashKeyKey)) { + $keyValue = '
'.base64_decode($keyValue).'
'; + } + if (preg_match("/$search/", $keyValue)) { + if (isset($results['key_value'])) { + array_push($results['key_value'], "$hashKeyKey = $keyValue"); + } else { + $results['key_value'] = array("$hashKeyKey = $keyValue"); + } + $match = true; + } + } + return array($results, $match); + } + + /* + * searchSet - search a set type key + */ + private static function searchSet ($key, $search) { + + $results = array(); + $match = false; + + $smembers = NagRedis::sMembers($key); + + foreach ($smembers as $smember) { + if (preg_match("/$search/", $smember)) { + if (isset($results['key_value'])) { + array_push($results['key_value'], $smember); + } else { + $results['key_value'] = array($smember); + } + $match = true; + } + } + return array($results, $match); + } + + /* + * searchRedisKey - given a key, determine it's type and look at it's data + */ + private static function searchRedisKey ($key, $search) { + /* Redis Types + * string: Redis::REDIS_STRING + * set: Redis::REDIS_SET + * list: Redis::REDIS_LIST + * zset: Redis::REDIS_ZSET + * hash: Redis::REDIS_HASH + * other: Redis::REDIS_NOT_FOUND + */ + $type = NagRedis::type($key); + switch ($type) { + case Redis::REDIS_HASH: + return self::searchHash($key, $search); + break; + case Redis::REDIS_SET: + return self::searchSet($key, $search); + break; + default: + error_log("ERROR: searchRedisKey: Unknown type: $key"); + } + return array(array(), false); + } + +} diff --git a/lib/class_mapping.ini b/lib/class_mapping.ini index 132e2ec..e9aaae3 100644 --- a/lib/class_mapping.ini +++ b/lib/class_mapping.ini @@ -23,6 +23,7 @@ NagTester = include/NagTester.class.php NRPECreate = include/NRPECreate.class.php NRPERpm = include/NRPERpm.class.php RevDeploy = include/RevDeploy.class.php +SaigonSearch = include/SaigonSearch.class.php VarnishCache = include/VarnishCache.class.php ;;;; diff --git a/views/nrpe_cfg_stage.php b/views/nrpe_cfg_stage.php index 5641d08..ef4308d 100644 --- a/views/nrpe_cfg_stage.php +++ b/views/nrpe_cfg_stage.php @@ -140,11 +140,11 @@ function( input ) { Command Timeout: - + Connection Timeout: - + diff --git a/views/search.php b/views/search.php new file mode 100644 index 0000000..72745c0 --- /dev/null +++ b/views/search.php @@ -0,0 +1,201 @@ + + + + + + + + + + 'command', + 'hostgroup' => 'hostgrp', + 'hostgroups' => 'hostgrp', + 'hosttemplate' => 'hosttemp', + 'hosttemplates' => 'hosttemp', + 'nodetemplate' => 'ngnt', + 'nodetemplates' => 'ngnt', + 'nrpecmds' => 'nrpecmd', + 'nrpeplugins' => 'nrpeplugin', + 'svcs' => 'svc', + 'timeperiods' => 'timeperiod', + 'contacttemplate' => 'contacttemp', + 'contacttemplates' => 'contacttemp', + 'contacts' => 'contact', + ); + + $cmdActionMap = array( 'ngnt' => 'manage' ); + + foreach ($viewData->searchResults as $deployment => $matches) { + if (isset($matches['match']) && $matches['match']) { + + echo "

Match in Deployment: $deployment

\n"; + + // Deployment Info Section + if (isset($matches['deployment_info']) || isset($matches['nonversioned'])) { + echo "Deployment Info\n"; + if (isset($matches['deployment_info']['key_name']) && count($matches['deployment_info']['key_name'])) { + echo "\n"; + } + if (isset($matches['deployment_info']['key_value']) && count($matches['deployment_info']['key_value'])) { + echo "\n"; + } + } + + // hostsearch* keys + $replaceMe = "/^".$matches['deployment_hash'].":/"; + if (isset($matches['nonversioned'])) { + if (isset($matches['nonversioned']['key_name']) && count($matches['nonversioned']['key_name'])) { + echo "\n"; + } + if (isset($matches['nonversioned']['key_value']) && count($matches['nonversioned']['key_value'])) { + echo "\n"; + } + } + + // All Versioned Keys + if (isset($matches['versioned'])) { + echo "

Versioned Info (version: ".$matches['version'].")

"; + $replaceMe = "/^".$matches['deployment_hash'].":".$matches['version'].":/"; + $lastLink = ''; + + if (isset($matches['versioned']['key_name']) && count($matches['versioned']['key_name'])) { + echo "$link\n"; + } + if (isset($matches['versioned']['key_value']) && count($matches['versioned']['key_value'])) { + echo "$link$link\n"; + } + } + + + } + } +?> + +
+

Search Data Dump:

+
+search =  search; ?>
+
+deployment =  deployment; ?>
+
+--------------------------------------------------------------------------------
+searchResults, true); ?>
+
+--------------------------------------------------------------------------------
+
+
+
+ + + + + + +
@@ -51,8 +72,14 @@ function getDeploymentMenu() {
+ +
+
+ Search: +
+
-
+
diff --git a/www/index.php b/www/index.php index 8d0f4ae..e5b22e2 100644 --- a/www/index.php +++ b/www/index.php @@ -20,7 +20,7 @@ - - + +