<%!
    from baruwa.lib.filters import totals
%>
<div class="alpos">
	<ul id="msgops">
		<li>${h.link_to(_('Bayes info'), url('server-status-bayes', serverid=c.server.id))}</li>
		<li>${h.link_to(_('Spamassassin lint'), url('server-status-sa', serverid=c.server.id))}</li>
		<li>${h.link_to(_('Inbound Queue'), url('server-status-mq-in', serverid=c.server.id))}</li>
	    <li>${h.link_to(_('Outbound Queue'), url('server-status-mq-out', serverid=c.server.id))}</li>
		<li>${h.link_to(_('Graphs'))}</li>
	</ul>
</div>
<div class="clear"></div>
<div class="sp10"></div>
<div id="content">
	<div class="grid_10">
	    <h3 class="head">${_("Todays stats")}</h3>
		<table class="sysstatus">
		<tbody>
		<tr>
			<td class="status_color_col">&nbsp;</td>
			<td class="status_name_col">${_("Processed")}</td>
			<td class="status_value_col">${c.status['total']|totals}</td>
		</tr>
		<tr>
			<td class="status_color_col"><div class="pie_6 pie"></div></td>
			<td class="status_name_col">${_("Clean")}</td>
			<td class="status_value_col">${c.status['clean_mail']|totals}</td>
		</tr>
		<tr>
			<td class="status_color_col"><div class="pie_1 pie"></div></td>
			<td class="status_name_col">${_("High scoring spam")}</td>
			<td class="status_value_col">${c.status['high_spam']|totals}</td>
		</tr>
		<tr>
			<td class="status_color_col"><div class="pie_2 pie"></div></td>
			<td class="status_name_col">${_("Low scoring spam")}</td>
			<td class="status_value_col">${c.status['spam_mail']|totals}</td>
		</tr>
		<tr>
			<td class="status_color_col"><div class="pie_10 pie"></div></td>
			<td class="status_name_col">${_("Virus infected")}</td>
			<td class="status_value_col">${c.status['virii']|totals}</td>
		</tr>
		<tr>
			<td class="status_color_col"><div class="pie_4 pie"></div></td>
			<td class="status_name_col">${_("Policy blocked")}</td>
			<td class="status_value_col">${c.status['otherinfected']|totals}</td>
		</tr>
		<tr>
			<td class="status_color_col">&nbsp;</td>
			<td class="status_name_col">${_("Inbound queues")}</td>
			<td class="status_value_col">${h.link_to(c.status['inq'], url('server-status-mq-in', serverid=c.server.id))}</td>
		</tr>
		<tr>
			<td class="status_color_col">&nbsp;</td>
			<td class="status_name_col">${_("Outbound queues")}</td>
			<td class="status_value_col">${h.link_to(c.status['outq'], url('server-status-mq-out', serverid=c.server.id))}</td>
		</tr>
		</tbody>
		</table>
		<div class="grid_10">
		    <h3 class="head">${_("Hardware status")}</h3>
			<div class="grid_10 drow alpha omega">
				% if not c.status['cpu'] is None:
				<div class="grid_4 alpha">${_('CPU')}</div>
				<div class="grid_6 omega">
					<div class="ometer">
						<div class="imeter" style="width:${"%d%%" % c.status['cpu']};">${"%d%%" % c.status['cpu']}</div>
					</div>
				</div>
				% else:
				<div class="cl">${_('Error reading CPU status')}</div>
				% endif
			</div>
			% if c.status['mem']['total']:
			<div class="grid_10 drow alpha omega">
				<div class="grid_4 alpha">${_('Memory')}</div>
				<div class="grid_6 omega">
					<div class="ometer">
						<div class="imeter" style="width:${"%d%%" % c.status['mem']['percent']};">${"%d%%" % c.status['mem']['percent']}</div>
					</div>
				</div>
			</div>
			<div class="grid_10 drow alpha omega">
				<div class="grid_4 cl alpha omega">${_('Total: %s') % h.format_byte_size(c.status['mem']['total'])}</div>
				<div class="grid_3 cl alpha omega">${_('Used: %s') % h.format_byte_size(c.status['mem']['used'])}</div>
				<div class="grid_3 cl alpha omega">${_('Free: %s') % h.format_byte_size(c.status['mem']['free'])}</div>
			</div>
			% else:
			<div class="grid_10 drow alpha omega">
				<div class="cl">${_('Error reading memory status.')}</div>
			</div>
			% endif
			<div class="grid_10 drow alpha omega">
				<h4 class="head">${_('Hard disks')}</h4>
			</div>
			% for disk in c.status['partitions']:
			<div class="grid_10 drow alpha omega">
				<div class="grid_2 alpha">${disk['device']}</div>
				<div class="grid_2">${disk['mountpoint']}</div>
				<div class="grid_6 omega">
					<div class="ometer">
						<div class="imeter" style="width:${"%d%%" % disk['percent']};">${"%d%%" % disk['percent']}</div>
					</div>
				</div>
			</div>
			<div class="grid_10 drow alpha omega">
				<div class="grid_4 cl alpha omega">${_('Total: %s') % h.format_byte_size(disk['total'])}</div>
				<div class="grid_3 cl alpha omega">${_('Used: %s') % h.format_byte_size(disk['used'])}</div>
				<div class="grid_3 cl alpha omega">${_('Free: %s') % h.format_byte_size(disk['free'])}</div>
			</div>
			% endfor
			% if not c.status['partitions']:
			<div class="grid_10 drow alpha omega">
				<div class="cl">${_('Error reading disk information')}</div>
			</div>
			% endif
			<div class="grid_10 drow alpha omega">
				<h4 class="head">${_('Network')}</h4>
			</div>
			% if c.status['net']:
			<div class="grid_10 drow alpha omega">
				<div class="grid_4 bold alpha omega">${_('Nic')}</div>
				<div class="grid_3 bold alpha omega">${_('Sent')}</div>
				<div class="grid_3 bold alpha omega">${_('Received')}</div>
			</div>
			% endif
			% for card in c.status['net']:
			% if c.status['net'][card]['bytes_sent'] and c.status['net'][card]['bytes_recv']:
			<div class="grid_10 drow alpha omega">
				<div class="grid_4 alpha omega">${card}</div>
				<div class="grid_3 alpha omega">${h.format_byte_size(c.status['net'][card]['bytes_sent'])}</div>
				<div class="grid_3 alpha omega">${h.format_byte_size(c.status['net'][card]['bytes_recv'])}</div>
			</div>
			% endif
			% endfor
			% if not c.status['net']:
			<div class="grid_10 drow alpha omega">
				<div class="cl">${_('Error reading network interface information')}</div>
			</div>
			% endif
		</div>
	</div>
	<div class="grid_6">
		<div class="grid_6">
			<h3 class="head">${_('Mail Graph')}</h3>
			<div style="width: 340px; height: 300px;">
				% if c.status['total']:
				<div id="chart" style="width: 340px; height: 264px;">
	            <img src="${url('status-host-graph', nodeid=c.server.id)}" alt="graph" />
				</div>
				% else:
				<div class="grid_6 drow alpha omega">${_('Not enough data available to generate graph.')}</div>
				% endif
	        </div>
		</div>
		<div class="grid_6">
			<h3 class="head">${_("System Status")}</h3>
			<table class="hoststatus">
				<tbody>
					<tr>
						<td>${_('Scanners')}</td>
						<td>
							${h.portable_img('imgs/status_ok.png', alt='x') if c.status['scanners'] else h.portable_img('imgs/caution.png', alt='x')}
					        &nbsp;${ungettext('%(s)d process', '%(s)d processes', c.status['scanners']) % dict(s=c.status['scanners'])}
						</td>
					</tr>
					<tr>
						<td>${_('MTA')}</td>
						<td>
							${h.portable_img('imgs/status_ok.png', alt='x') if c.status['mta'] else h.portable_img('imgs/caution.png', alt='x')}
					        &nbsp;${ungettext('%(mta)d process', '%(mta)d processes', c.status['mta']) % dict(mta=c.status['mta'])}
						</td>
					</tr>
					<tr>
						<td>${_('Anti-Virus')}</td>
						<td>
							${h.portable_img('imgs/status_ok.png', alt='x') if c.status['av'] else h.portable_img('imgs/caution.png', alt='x')}
					        &nbsp;${ungettext('%(a)d process', '%(a)d processes', c.status['av']) % dict(a=c.status['av'])}
						</td>
					</tr>
					<tr>
						<td>${_('CPU Load (1 / 5 / 15 mins)')}</td>
						<td>
							${h.portable_img('imgs/status_ok.png', alt='x') if c.status['load'][0] <= 15 else h.portable_img('imgs/caution.png', alt='x')}
							&nbsp;${"%.2f / %.2f / %.2f" % c.status['load'] }
						</td>
					</tr>
					<tr>
						<td>${_('System Uptime')}</td>
						<td>${c.status['uptime']}</td>
					</tr>
					<tr>
						<td>${_('System Time')}</td>
						<td>${c.status['time']}</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>
</div>

<%def name="title()">\
${_('Status :: Node status :: %(server)s') % dict(server=c.server.hostname)}
</%def>

<%def name="heading()">\
${_('Status :: Node status :: %(server)s') % dict(server=c.server.hostname)}
</%def>

<%def name="headers()">\
</%def>
<%def name="localscripts()">\
</%def>
<%inherit file="/base.html"/>
