<%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 => '';
	$server => '';
	$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', srv=> $server, af=>$af), %ARGS);
	my $t2  = $m->comp('/lib/rrdplots:calc_t2',
		lastval=> $m->comp('/lib/rrdplots:last_val', srv=> $server, af=>$af), %ARGS);

	$period = $m->comp('/lib/rrdplots:calc_period',
		lastval=> $m->comp('/lib/rrdplots:last_val', srv=> $server, 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="Servers" action="/dns-servmon/server/plot" method="get">
	<&| /lib/fillform, subs => \%ARGS &>
		<div id="fillform_servers" >
			<table>
				<tr>
					<td> <& /lib/rrdplots:select_stype &> </td>
					<td>of<& /lib/rrdplots:select_server &></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="server_overview_backlink"> Server plot for <b><% $server %></b> (<% $af %>) [ serving:
% my %myARGS = map { $_ => $ARGS{$_}} grep {/^(af|type|tstart|tstop)$/} keys %ARGS;
% foreach my $domain ($m->comp('/lib/rrdplots:server_domains',srv => $server, af => $af)) {
<a href="<& /lib/url, path => '/dns-servmon/domain/plot', query => { %myARGS, domain => ${domain} } &> "><% $domain %></a> 
% }
]

</div>

<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="server_<% ${server} %>"></div></div><script language="javascript" type="text/javascript">
<& /lib/ajax, prefix => '/dns-servmon', throbber => '/images/dnsmon/throbber.gif', comp=>'SELF:plot_server', parameters => { srv => $server, type => $type, %ARGS}, update => "server_${server}", javascript => 1   &>
</script>

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


<%method plot_server>
<%attr>
ajax => 1
</%attr>
<%args>
	$srv
	$type
	$period => '';
	$shift => 0;
	$af => 'ipv4';
</%args>
<%perl>

	my $t1  = $m->comp('/lib/rrdplots:calc_t1',
		lastval=> $m->comp('/lib/rrdplots:last_val', srv=> $srv, af=>$af), %ARGS);
	my $t2  = $m->comp('/lib/rrdplots:calc_t2',
		lastval=> $m->comp('/lib/rrdplots:last_val', srv=> $srv, af=>$af), %ARGS);
	my %myARGS;

	$period = $m->comp('/lib/rrdplots:calc_period',
		lastval=> $m->comp('/lib/rrdplots:last_val', srv=> $srv), 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_server', srv => $srv, af=>$af)) {
% if ($type eq 'drops') {
	<& /lib/rrdplots:plot_s_drops, srv=>$srv, start=>$t1, stop=>$t2, fuzzy=>0, af=>$af, %myARGS &>
% } elsif ($type eq 'instance')  {
	<& /lib/rrdplots:plot_s_instance, srv=>$srv, start=>$t1, stop=>$t2, fuzzy=>0, af=>$af, %myARGS &>
% } elsif ($type eq 'delays-10')  {
	<& /lib/rrdplots:plot_s_delay, type=> $type, srv=>$srv, start=>$t1, stop=>$t2, fuzzy=>0, opt_h=>4000, maxms=>10, af=>$af, %myARGS &>
% } elsif ($type eq 'delays-50')  {
	<& /lib/rrdplots:plot_s_delay, type=> $type, srv=>$srv, start=>$t1, stop=>$t2, fuzzy=>0, opt_h=>4000, maxms=>50, af=>$af, %myARGS &>
% } elsif ($type eq 'delays-500')  {
	<& /lib/rrdplots:plot_s_delay, type=> $type, srv=>$srv, start=>$t1, stop=>$t2, fuzzy=>0, opt_h=>4000, maxms=>500, af=>$af, %myARGS &>
% } else {
	<& /lib/rrdplots:plot_s_delay, srv=>$srv, start=>$t1, stop=>$t2, fuzzy=>0, af=>$af, %myARGS &>
%}

% } else {
<p><strong>This server has no <% $af %> coverage by DNSMon</strong></p>
% }
</%method>
