<%doc>
############################################################################
###    (C)opyright 2003 - 2008 RIPE NCC
###    This file is part of DNSMon
###
###    DNSMon 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 3 of the License, or
###    (at your option) any later version.
###
###    DNSMon 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 DNSMon.  If not, see <http://www.gnu.org/licenses/>.
############################################################################
</%doc>
<%args>
	$day => '';
	$month => '';
	$year => '';
	$hour => '';
	$period => '';
	$probe => '';
	$type => 'delay'; 
	$shift => 0;
	$tstart => 0;
	$tstop => 0;
	$af => 'ipv4';
	$refresh => '';
</%args>

<%perl>
	my $t1 = $m->comp('/lib/rrdplots:calc_t1',
		lastval=>$m->comp('/lib/rrdplots:last_val_probe', 
			probe=>$probe, af=>$af), %ARGS);
	my $t2 = $m->comp('/lib/rrdplots:calc_t2',
		lastval=>$m->comp('/lib/rrdplots:last_val_probe', 
			probe=>$probe, af=>$af), %ARGS);

	$period = $m->comp('/lib/rrdplots:calc_period',
		lastval=>$m->comp('/lib/rrdplots:last_val_probe', probe=>$probe, af=>$af),
		t1=>$t1, t2=>$t2, period=>$period, shift=>$shift);

	$ARGS{'hour'}   = $t1->hour;
	$ARGS{'day'}    = $t1->mday;
	$ARGS{'month'}  = $t1->mon;
	$ARGS{'year'}   = $t1->year;
	$ARGS{'period'} = $period;
	$ARGS{'type'} = $type;
	$ARGS{'af'} = $af;
	$ARGS{'tstart'} = $t1->epoch;
	$ARGS{'tstop'} = $t2->epoch;

</%perl>
<form name="Probes" action="/dns-servmon/probe/plot" method="get" >
	<&| /lib/fillform, subs => \%ARGS &>
		<div id="fillform_probes" >
			<table summary="Parameter form to select custom plots">
				<tr>
					<td> <& /lib/rrdplots:select_type &> </td>
					<td>of<& /lib/rrdplots:select_probe &></td>
					<td><& /lib/rrdplots:select_af&></td>
					<td>from <& /lib/rrdplots:select_time &></td>
					<td>for<& /lib/rrdplots:select_period &></td>
					<td> &nbsp;<input type="submit" value="show" name="plot" /></td>
				</tr>
			</table>
		</div>
	</&>

% if ($TICKET) {
	<div id="select_select_refresh_plot"><& /lib/rrdplots:select_refresh_plot &></div>
% }
	<div id="select_shift"> Show other time frame: <& /lib/rrdplots:select_shift &> </div>

</form>

<div id="warn_long_timeframe"><& /lib/rrdplots:warn_long_timeframe, start => $t1, stop => $t2 &></div>

% $m->flush_buffer;
<div class="center"><div class="plot" id="probe_<% ${probe} %>"></div></div><script language="javascript" type="text/javascript">
<& /lib/ajax, prefix => '/dns-servmon', throbber => '/images/dnsmon/throbber.gif', comp=>'SELF:plot_probe', parameters => { probe => $probe, type => $type, %ARGS}, update => "probe_${probe}"  &>
</script>

% if ($TICKET) {
<div id="rislink">
<& /lib/rrdplots:ris_url, name => $probe, af => $af, start=>$t1, stop=>$t2 &>
</div>
% }

<%method plot_probe>
<%attr>
ajax => 1
</%attr>
<%args>
	$probe
	$type
	$period => '';
	$shift => 0;
	$af => 'ipv4';
</%args>
<%perl>
	my $t1 = $m->comp('/lib/rrdplots:calc_t1',
		lastval=>$m->comp('/lib/rrdplots:last_val_probe', 
			probe=>$probe, af=>$af), %ARGS);
	my $t2 = $m->comp('/lib/rrdplots:calc_t2',
		lastval=>$m->comp('/lib/rrdplots:last_val_probe', 
			probe=>$probe, af=>$af), %ARGS);
	my %myARGS;

	$period = $m->comp('/lib/rrdplots:calc_period',
		lastval=>$m->comp('/lib/rrdplots:last_val_probe', probe=>$probe, af=>$af),
		t1=>$t1, t2=>$t2, period=>$period, shift=>$shift);

	$ARGS{'hour'}   = $t1->hour;
	$ARGS{'day'}    = $t1->mday;
	$ARGS{'month'}  = $t1->mon;
	$ARGS{'year'}   = $t1->year;
	$ARGS{'period'} = $period;
	$ARGS{'type'} = $type;
	$ARGS{'af'} = $af;

	if ($TICKET && exists($ARGS{refresh})) {
		$myARGS{'refresh'} = 'yes';
	}

</%perl>
% if ($m->comp('/lib/rrdplots:known_probe', mon => $probe, af=>$af)) {
% if ($type eq 'drops') {
	<& /lib/rrdplots:plot_p_drops, probe=>$probe, start=>$t1, stop=>$t2, fuzzy=>0, af=>$af, %myARGS &>
% } elsif ($type eq 'delays-10')  {
	<& /lib/rrdplots:plot_p_delay, probe=>$probe, start=>$t1, stop=>$t2, fuzzy=>0, opt_h=>4000, maxms=>10, af=>$af, %myARGS &>
% } elsif ($type eq 'delays-50')  {
	<& /lib/rrdplots:plot_p_delay, probe=>$probe, start=>$t1, stop=>$t2, fuzzy=>0, opt_h=>4000, maxms=>50, af=>$af, %myARGS &>
% } elsif ($type eq 'delays-500')  {
	<& /lib/rrdplots:plot_p_delay, probe=>$probe, start=>$t1, stop=>$t2, fuzzy=>0, opt_h=>4000, maxms=>500, af=>$af, %myARGS &>
% } else {
	<& /lib/rrdplots:plot_p_delay, probe=>$probe, start=>$t1, stop=>$t2, fuzzy=>0, af=>$af, %myARGS &>
% }
% } else {
<p><strong>This DNSMon probe does not cover <% $af %> measurements</strong></p>
% }
</%method>
