This repository has been archived by the owner on Apr 4, 2022. It is now read-only.
forked from etsy/opsweekly
-
Notifications
You must be signed in to change notification settings - Fork 1
/
search.php
160 lines (140 loc) · 7.11 KB
/
search.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
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
<?php
include_once("phplib/base.php");
$query = ((isset($_GET['query'])) && ($_GET['query'] != "")) ? db::escape($_GET['query']) : null;
if ($query) {
// Try and pick out our filters
if (preg_match('/^((?P<context>\w+):\s)?(?P<term>.*)/i', $query, $matches) === false) {
$header = "Search Failed";
$no_search = true;
} else {
$term = $matches['term'];
$context = $matches['context'];
$page = isset($_GET['page']) ? ((int) $_GET['page']) : 1;
// Match on the 'context' for special searches that are more specific.
switch($context) {
case 'service':
case 'host':
$format_filter = ($context == 'host') ? 'hostname' : 'service';
$title = "{$context} '{$term}'";
$header = "Results from on call reports for {$context} '{$term}'";
if (!$results = handleSearch($context, $term)) break;
$html = formatSearchResults($results, $format_filter, $term, $search_results_per_page,($page-1)*$search_results_per_page);
$html .= formatPagination($page, count($results));
// Stats calculation for on call items
foreach ($results as $n) {
$status_agg[$n['state']]++;
$status_agg_total++;
$tag_agg_normalised[$nagios_tag_category_map[$n['tag']]]++;
$tag_agg[$n['tag']]++;
$tag_agg_total++;
$time_counts[$n['timestamp']]++;
}
break;
case 'report':
$title = "report '{$term}'";
$header = "Results from weekly reports for '{$term}'";
if (!$results = handleSearch('generic_reports', $term)) break;
$html = formatSearchResults($results, 'report', $term, $search_results_per_page,($page-1)*$search_results_per_page);
$html .= formatPagination($page, count($results));
break;
case 'meeting':
$title = "meeting notes containing '{$term}'";
$header = "Results from meeting notes for '{$term}'";
if (!$results = handleSearch('meeting_notes', $term)) break;
$html = formatSearchResults($results, 'notes', $term, $search_results_per_page,($page-1)*$search_results_per_page);
$html .= formatPagination($page, count($results));
break;
default:
$everything = true;
$title = $term = $matches[0];
$header = "Results from everything for '{$term}'";
// A little bit of everything.
if ($results = handleSearch('service', $term)) {
$html = "<h3>Services</h3>";
$html .= formatSearchResults($results, 'service', $term, 5);
$html .= printMoreSearchTypeButton('service', $term);
}
if ($results = handleSearch('host', $term)) {
$html .= "<h3>Hosts</h3>";
$html .= formatSearchResults($results, 'hostname', $term, 5);
$html .= printMoreSearchTypeButton('host', $term);
}
if ($results = handleSearch('generic_reports', $term)) {
$html .= "<h3>Weekly Reports</h3>";
$html .= formatSearchResults($results, 'report', $term, 3);
$html .= printMoreSearchTypeButton('report', $term);
}
if ($results = handleSearch('meeting_notes', $term)) {
$html .= "<h3>Meeting Notes</h3>";
$html .= formatSearchResults($results, 'notes', $term, 2);
$html .= printMoreSearchTypeButton('meeting', $term);
}
break;
}
}
} else {
$header = "Search";
$no_search = true;
}
$page_title = getTeamName() . " Weekly Updates - Search results for {$title}";
include_once('phplib/header.php');
include_once('phplib/nav.php');
?>
<div class="container">
<h1><?php echo $header ?></h1>
<div class="row">
<div class="span12">
<?php
if ($no_search) {
echo insertNotify("error", "No search term was entered, please enter something to search for. ");
echo insertNotify("info", "<b>Tips:</b> You can either enter a phrase for a best effort search of weekly reports and on call data, or
specific host/service alerts. Click the search box for more information");
} else {
if ($html) {
if (!$everything) {
echo "<p class='lead'>" . count($results). " results total</p>";
}
echo $html;
// Stats for on call items
if ($context == 'service' || $context == 'host') {
echo "<h3>Stats for these search results</h3>";
$stats_html = "<h4>Alert Status Distribution</h4>";
$stats_html .= renderStatusProgressBar($status_agg, $status_agg_total);
$stats_html .= "<br />";
$stats_html .= "<h4>Tag Status Summary</h4><p>Breakdown of the tags applied to the notifications in this search</p>";
$stats_html .= renderTagTable($tag_agg, $tag_agg_total, $nagios_alert_tags);
$stats_html .= "</table><p>Breakdown of the tags applied (normalised)</p>";
$stats_html .= renderTagTable($tag_agg_normalised, $tag_agg_total, $nagios_tag_categories);
$stats_html .= "</table><br />";
echo $stats_html;
?>
<h3>Notification Time Map</h3>
<p>Grids read from top to bottom through hours, the darker the more alerts were received <small>(Hover over the blocks for a count)</small></p>
<div id="cal-heatmap"></div>
<script type="text/javascript">
var time_data = <?php echo json_encode($time_counts) ?>;
var cal = new CalHeatMap();
cal.init({
data: time_data,
domain : "month",
start: new Date(<?php echo date("U", strtotime("-1 year")) ?>*1000),
subDomain : "day",
range : 13,
itemName: ["notification", "notifications"],
domainGutter: 2
});
</script>
<br />
<?php
}
} else {
echo insertNotify("error", "Nothing was found for that search. If you believe this is in error, you may be right. Complain to the developer. ");
}
}
?>
</div>
</div>
</div>
<?php include_once('phplib/footer.php'); ?>
</body>
</html>