-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility.php
More file actions
178 lines (168 loc) · 6.18 KB
/
utility.php
File metadata and controls
178 lines (168 loc) · 6.18 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/*
*
* aql - Active Query Listing
*
* Copyright (C) 2018 Kevin Benton - kbcmdba [at] gmail [dot] com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
namespace com\kbcmdba\aql ;
require_once 'vendor/autoload.php';
use com\kbcmdba\aql\Libs\Tools ;
/**
* Since parameters directly map to query options...
*
* @param string $optionName
* @param string $columnName
* @param string $default
* Value of 'any' tells this routine not to do anything in the event that the user doesn't supply a value.
* @param string $limits
*/
function processParam($optionName, $columnName, $default, &$limits)
{
switch (Tools::param($optionName)) {
case 'any':
// Don't do anything here. This is a special case when it's much
// easier to not specify the column at all.
break;
case '1':
$limits .= " AND $columnName = 1";
break;
case '0':
$limits .= " AND $columnName = 0";
break;
default:
if ('any' !== $default) {
$limits .= " AND $columnName = $default";
}
break;
}
}
/**
* Process the query list for a given host
*
* @param mixed $js
* @param string $hostname
* @param string $baseUrl
* @param integer $alertCritSecs
* @param integer $alertWarnSecs
* @param integer $alertInfoSecs
* @param integer $alertLowSecs
*/
function processHost(&$js, $hostname, $baseUrl, $alertCritSecs, $alertWarnSecs, $alertInfoSecs, $alertLowSecs)
{
$debug = ( Tools::param('debug')==='1' ) ? '&debug=1' : '' ;
$debugLocks = ( Tools::param('debugLocks')==='1' ) ? '&debugLocks=1' : '' ;
$blockNum = $js['Blocks'] ;
$js['Blocks'] ++ ;
$url = "$baseUrl?hostname=$hostname&alertCritSecs=$alertCritSecs&alertWarnSecs=$alertWarnSecs&alertInfoSecs=$alertInfoSecs&alertLowSecs=$alertLowSecs$debug$debugLocks" ;
// Build individual AJAX call with immediate callback (no waiting for others)
$js['AjaxCalls'] .= <<<JSAJAX
pendingHosts[ '$hostname' ] = true ;
var ajaxStart_{$blockNum} = Date.now() ;
\$.getJSON( "$url" )
.done( function( data ) {
delete pendingHosts[ '$hostname' ] ;
var totalMs = Date.now() - ajaxStart_{$blockNum} ;
var serverMs = ( data && data.renderTimeData && data.renderTimeData.total ) ? data.renderTimeData.total : null ;
var networkMs = ( serverMs !== null ) ? Math.round( Math.max( 0, totalMs - serverMs ) ) : null ;
ajaxRenderTimes[ '$hostname' ] = {
total: totalMs,
server: serverMs,
network: networkMs,
dbType: ( data && data.dbType ) ? data.dbType : 'MySQL',
renderTimeData: ( data && data.renderTimeData ) ? data.renderTimeData : null,
error: false
} ;
myCallback( $blockNum, data ) ;
} )
.fail( function( jqXHR, textStatus, errorThrown ) {
delete pendingHosts[ '$hostname' ] ;
var totalMs = Date.now() - ajaxStart_{$blockNum} ;
ajaxRenderTimes[ '$hostname' ] = {
total: totalMs,
server: null,
network: null,
dbType: 'Unknown',
renderTimeData: null,
error: true,
errorText: textStatus
} ;
console.error( 'AJAX failed for $hostname:', textStatus, errorThrown ) ;
// Show error in tables so user knows this host failed
var errorRow = '<tr class="errorNotice"><td>$hostname</td><td>9</td><td colspan="12">Connection failed: ' + textStatus + '</td></tr>' ;
\$( errorRow ).prependTo( '#nwprocesstbodyid' ) ;
\$( errorRow ).prependTo( '#fullprocesstbodyid' ) ;
trackHostByDbType( 'MySQL' ) ;
trackLevelByDbType( 'MySQL', 9, 1, '$hostname' ) ;
updateDbTypeOverview() ;
updateScoreboard() ;
} )
.always( onAjaxComplete ) ;
JSAJAX;
}
/**
* Get the radio choices users are given.
*
* @param string $label
* @param string $name
* @param string $defaultValue
* @return string
*/
function getChoices($label, $name, $defaultValue)
{
$checkedValue = Tools::param($name);
if (! (isset($checkedValue) && ($checkedValue !== ''))) {
$checkedValue = $defaultValue;
}
$yesChecked = ('1' === $checkedValue) ? 'checked="checked"' : '';
$noChecked = ('0' === $checkedValue) ? 'checked="checked"' : '';
$anyChecked = ('any' === $checkedValue) ? 'checked="checked"' : '';
$yes = "<input type=\"radio\" name=\"$name\" value=\"1\" $yesChecked />";
$no = "<input type=\"radio\" name=\"$name\" value=\"0\" $noChecked />";
$any = "<input type=\"radio\" name=\"$name\" value=\"any\" $anyChecked />";
return ("<tr><td>$label</td><td>$yes</td><td>$no</td><td>$any</td></tr>");
}
/**
* Process the and/or radios
*
* @param string $name
* @param string $value
* @param
* string &$result
*/
function processAndOr($name, $value, &$checked, &$result)
{
if (strtoupper(Tools::param($name)) === strtoupper($value)) {
$checked = 'checked="checked"';
$result = $value;
}
}
/**
* Process individual values of the SELECT/OPTION list
*
* @param string $label
* @param string $value
* @param
* mixed &$list
*/
function processSelectOption($name, $label, $value, &$list)
{
$exists = in_array($value, Tools::params($name), true);
$checked = ($exists) ? 'checked="checked"' : '';
$list .= "<option value=\"$value\" $checked>$label</option>";
}