-
Notifications
You must be signed in to change notification settings - Fork 18
/
testconfig.php
84 lines (74 loc) · 2.19 KB
/
testconfig.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
This File can be used to test templates, on which host/service they match.
PHP version 5
@category Debug_File
@package Default
@author Philip Griesbacher <griesbacher@consol.de>
@license http://opensource.org/licenses/gpl-license.php GNU Public License
@link https://github.com/ConSol/histou
**/
require_once 'histou/basic.php';
require_once 'histou/database.php';
require_once 'histou/folder.php';
$lineEnd = '';
if (isset($argv[1]) && !empty($argv[1])) {
$requestedTemplate = $argv[1];
$lineEnd = "\n";
} elseif (isset($_GET["filename"]) && !empty($_GET["filename"])) {
$requestedTemplate = $_GET["filename"];
$lineEnd = '<br>';
} else {
print_r(
"Arguement is missing!
When used by URL pass the Templatefilename by the Postparameter 'filename'.
On Commandline pass it as the first argument"
);
exit(1);
}
parsIni('histou.ini');
$influx = new Influxdb(URL);
$series = getSeries($influx);
$availableTemplates = Folder::loadFolders(
array(CUSTOM_TEMPLATE_FOLDER, DEFAULT_TEMPLATE_FOLDER)
);
$templatesToCheck = array();
foreach ($availableTemplates as $template) {
if ($template->getSimpleFileName() == $requestedTemplate
|| $template->getFileName() == $requestedTemplate
) {
array_push($templatesToCheck, $template);
}
}
if (count($templatesToCheck) == 0) {
print_r('No template found with this name: '.$requestedTemplate.$lineEnd);
exit(0);
}
foreach ($templatesToCheck as $template) {
$hits = array();
foreach ($series as $tablename) {
if ($template->matchesTablename($tablename)) {
array_push($hits, preg_split('/&(?!.*&).*/', $tablename)[0]);
}
}
$hits = array_unique($hits);
print_r($template->getPath().'/'.$template->getFileName().":".$lineEnd);
print_r('----'.$lineEnd);
foreach ($hits as $hit) {
print_r($hit.$lineEnd);
}
}
/**
Gets all series names from influxdb.
@param object $database Influxdb Object.
@return List of names.
**/
function getSeries($database)
{
$list = array();
$request = $database->makeRequest("SHOW SERIES");
foreach ($request[0]['series'] as $tablename) {
array_push($list, $tablename['name']);
}
return $list;
}