Skip to content

Commit 4c66aa5

Browse files
committed
histou: use check_interval to fine tune gaps in grafana graphs
1 parent a89a1b5 commit 4c66aa5

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

lib/Thruk/Utils.pm

+23-1
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,8 @@ sub get_histou_url {
15661566
next unless defined $obj->{$type};
15671567
my $regex = $c->config->{'grafana_url_regex'};
15681568
if($obj->{$type} =~ m%$regex%mx) {
1569-
return(proxifiy_url($c, $obj, $obj->{$type}));
1569+
my $url = _enhance_histou_url($c, $obj->{$type}, $obj);
1570+
return(proxifiy_url($c, $obj, $url));
15701571
}
15711572
}
15721573

@@ -2010,6 +2011,7 @@ sub get_action_url {
20102011
return($action_url);
20112012
}
20122013
elsif($action_url =~ m/\/histou\.js\?/mx || $action_url =~ m/\/grafana\//mx) {
2014+
$action_url = _enhance_histou_url($c, $action_url, $obj);
20132015
my $custvars = get_custom_vars($c, $obj, $obj_prefix);
20142016
$action_url =~ s/&/&/gmx;
20152017
$action_url =~ s/&/&/gmx;
@@ -4254,6 +4256,26 @@ sub get_affected_backends {
42544256
return([sort keys %{$affected_backends}]);
42554257
}
42564258

4259+
##############################################
4260+
# replaces dark themen in the histou url and
4261+
# sets the spannulls value
4262+
sub _enhance_histou_url {
4263+
my($c, $url, $obj) = @_;
4264+
4265+
return($url) unless $url =~ m/histou.js/mx;
4266+
4267+
if(($c->stash->{'theme'}//'') =~ m/dark/mxi) {
4268+
$url =~ s/\&theme=light/\&theme=dark/gmx;
4269+
}
4270+
4271+
if($obj->{'check_interval'}) {
4272+
my $interval_length = $c->stash->{'pi_detail'}->{$obj->{'peer_key'}}->{'interval_length'} // 60;
4273+
$url = $url.'&spannulls='.($obj->{'check_interval'} * $interval_length * 2);
4274+
}
4275+
4276+
return($url);
4277+
}
4278+
42574279
##############################################
42584280

42594281
1;

root/thruk/javascript/thruk-3.20.2.js

-9
Original file line numberDiff line numberDiff line change
@@ -10193,15 +10193,6 @@ function set_histou_img(start, end, id, source, skip_hash) {
1019310193
var getParamTo = "&to=" + (toUnixtime(end)*1000);
1019410194
var newUrl = histou_frame_url + getParamFrom + getParamTo + '&panelId='+source;
1019510195

10196-
if(theme.match(/dark/i)) {
10197-
newUrl = newUrl.replace("&theme=light", "")
10198-
newUrl = newUrl+'&theme=dark';
10199-
histou_url = histou_url.replace("&theme=light", "&theme=dark");
10200-
} else {
10201-
newUrl = newUrl.replace("&theme=light", "")
10202-
newUrl = newUrl+'&theme=light';
10203-
}
10204-
1020510196
//add timerange to iconlink, so the target graph matches the preview
1020610197
jQuery("#histou_graph_link").attr("href", url_prefix + "#" + histou_url + getParamFrom + getParamTo);
1020710198

ssi/status-header.ssi-pnp

-9
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@ jQuery(document).ready(function() {
1616
popup_pos_x = e.pageX - popup_width - 5;
1717
}
1818

19-
if(theme.match(/dark/i)) {
20-
url = url.replace("&theme=light", "&theme=dark");
21-
var link = jQuery(e.target).parent("A").attr("href");
22-
if(link) {
23-
link = link.replace("&theme=light", "&theme=dark");
24-
jQuery(e.target).parent("A").attr("href", link);
25-
}
26-
}
27-
2819
var showPopup = function(url) {
2920
jQuery("#tooltip").remove();
3021
jQuery("body").append("<div id='tooltip'><iframe src='"+url+"' width='"+popup_width+"' height='"+popup_height+"' frameBorder='0' scrolling='no' onload='resizeGraphIFrame(this)'><\/iframe><\/div>");

templates/_histou_graph.tt

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
[% USE date %]
22
[% histou_frame_url = histou_url.replace('/dashboard/', '/dashboard-solo/').replace('/d/', '/d-solo/') %]
3-
[% IF theme.match('/dark/') %]
4-
[% histou_url = histou_url.replace('&theme=light', '&theme=dark') %]
5-
[% END %]
63
<script>
74
var histou_url = "[% histou_url %]";
85
var histou_frame_url = "[% histou_frame_url %]";

0 commit comments

Comments
 (0)