<%!
    from baruwa.lib.filters import totals
%>
<div class="row-fluid">
	<div class="span1 hidden-phone"></div>
	<div class="span10">
		<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="span1 hidden-phone"></div>
</div>
<div class="space-6"></div>
<div class="row-fluid">
	<div class="span1 hidden-phone"></div>
	<div class="span6">
		<h3 class="head smaller lighter blue">${_("Todays stats")}</h3>
		<table class="table table-bordered table-condensed table-hover table-striped">
		<tbody>
		<tr>
			<td class="status_name_col">${_("Processed")}</td>
			<td class="status_value_col"><span class="badge badge-info">${c.status['total']|totals}</span></td>
		</tr>
		<tr>
			<td class="status_name_col">${_("Clean")}</td>
			<td class="status_value_col"><span class="badge badge-success">${c.status['clean_mail']|totals}</span></td>
		</tr>
		<tr>
			<td class="status_name_col">${_("High scoring spam")}</td>
			<td class="status_value_col"><span class="badge badge-highspam">${c.status['high_spam']|totals}</span></td>
		</tr>
		<tr>
			<td class="status_name_col">${_("Low scoring spam")}</td>
			<td class="status_value_col"><span class="badge badge-spam">${c.status['spam_mail']|totals}</span></td>
		</tr>
		<tr>
			<td class="status_name_col">${_("Virus infected")}</td>
			<td class="status_value_col"><span class="badge badge-virii">${c.status['virii']|totals}</span></td>
		</tr>
		<tr>
			<td class="status_name_col">${_("Policy blocked")}</td>
			<td class="status_value_col"><span class="badge badge-infected">${c.status['otherinfected']|totals}</span></td>
		</tr>
		<tr>
			<td class="status_name_col">${_("Inbound queues")}</td>
			<td class="status_value_col"><span class="badge badge-info">${h.link_to(c.status['inq'], url('server-status-mq-in', serverid=c.server.id))}</span></td>
		</tr>
		<tr>
			<td class="status_name_col">${_("Outbound queues")}</td>
			<td class="status_value_col"><span class="badge badge-info">${h.link_to(c.status['outq'], url('server-status-mq-out', serverid=c.server.id))}</span></td>
		</tr>
		</tbody>
		</table>
	</div>
	<div class="span4">
		<div class="row-fluid">
			<h3 class="head smaller lighter blue">${_('Mail Graph')}</h3>
			<div class="span12">
				% if c.status['total']:
				<div id="chart">
					<noscript>
						<img src="${url('status-host-graph', nodeid=c.server.id)}" alt="graph" />
					</noscript>
				</div>
				% else:
				${_('Not enough data available to generate graph.')}
				% endif
			</div>
		</div>
	</div>
	<div class="span1 hidden-phone"></div>
</div>
<div class="row-fluid">
	<div class="span1 hidden-phone"></div>
	<div class="span6">
		<h3 class="head smaller lighter blue">${_("Hardware status")}</h3>
		<div class="row-fluid">
			% if not c.status['cpu'] is None:
			<div class="span6">${_('CPU')}</div>
			<div class="span6">
				<div class="progress" data-percent="${"%d%%" % c.status['cpu']}">
					<div class="bar" style="width: ${"%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="row-fluid">
			<div class="span6">${_('Memory')}</div>
			<div class="span6">
				<div class="progress" data-percent="${"%d%%" % c.status['mem']['percent']}">
					<div class="bar" style="width: ${"%d%%" % c.status['mem']['percent']};"></div>
				</div>
			</div>
		</div>
		<div class="row-fluid">
			<div class="span4 half">${_('Total: %s') % h.format_byte_size(c.status['mem']['total'])}</div>
			<div class="span4 half">${_('Used: %s') % h.format_byte_size(c.status['mem']['used'])}</div>
			<div class="span4 half">${_('Free: %s') % h.format_byte_size(c.status['mem']['free'])}</div>
		</div>
		% else:
		<div class="row-fluid">
			<div class="span12">${_('Error reading memory status.')}</div>
		</div>
		% endif
		<div class="row-fluid">
			<h4 class="head">${_('Hard disks')}</h4>
		</div>
		% for disk in c.status['partitions']:
		<div class="row-fluid">
			<div class="span2">${disk['device']}</div>
			<div class="span2">${disk['mountpoint']}</div>
			<div class="span8">
				<div class="progress" data-percent="${"%d%%" % disk['percent']}">
					<div class="bar" style="width: ${"%d%%" % disk['percent']};"></div>
				</div>
			</div>
		</div>
		<div class="row-fluid">
			<div class="span4 half">${_('Total: %s') % h.format_byte_size(disk['total'])}</div>
			<div class="span4 half">${_('Used: %s') % h.format_byte_size(disk['used'])}</div>
			<div class="span4 half">${_('Free: %s') % h.format_byte_size(disk['free'])}</div>
		</div>
		% endfor
		% if not c.status['partitions']:
		<div class="row-fluid">
			<div class="span12">${_('Error reading disk information')}</div>
		</div>
		% endif
		<div class="row-fluid">
			<h4 class="head">${_('Network')}</h4>
		</div>
		% if c.status['net']:
		<div class="row-fluid">
			<div class="span6 half">${_('Nic')}</div>
			<div class="span3 half">${_('Sent')}</div>
			<div class="span3 half">${_('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="row-fluid">
			<div class="span6 half">${card}</div>
			<div class="span3 half">${h.format_byte_size(c.status['net'][card]['bytes_sent'])}</div>
			<div class="span3 half">${h.format_byte_size(c.status['net'][card]['bytes_recv'])}</div>
		</div>
		% endif
		% endfor
		% if not c.status['net']:
		<div class="row-fluid">
			<div class="span12">${_('Error reading network interface information')}</div>
		</div>
		% endif
	</div>
	<div class="span4">
		<h3 class="head smaller lighter blue">${_("System Status")}</h3>
		<table class="table table-bordered table-condensed table-hover table-striped">
			<tbody>
				<tr>
					<td>${_('Scanners')}</td>
					<td>
						${h.literal('<i class="icon-ok green"></i>') if c.status['scanners'] else h.literal('<i class="icon-remove red"></i>')}
				        &nbsp;${ungettext('%(s)d process', '%(s)d processes', c.status['scanners']) % dict(s=c.status['scanners'])}
					</td>
				</tr>
				<tr>
					<td>${_('MTA')}</td>
					<td>
						${h.literal('<i class="icon-ok green"></i>') if c.status['mta'] else h.literal('<i class="icon-remove red"></i>')}
				        &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.literal('<i class="icon-ok green"></i>') if c.status['av'] else h.literal('<i class="icon-remove red"></i>')}
				        &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.literal('<i class="icon-ok green"></i>') if c.status['load'][0] <= 15 else h.literal('<i class="icon-remove red"></i>')}
						&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 class="span1 hidden-phone"></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()">\
<script type="text/javascript">
var rdata = ${c.chart_data|n};
</script>
</%def>

<%def name="submenu()">
<div class="navbar navbar-static-top">
    <div class="navbar-inner">
        <div class="nav-collapse collapse">
            <ul class="nav navbar-nav">
                <li class="nav_item"><a href="${url('mailq-status')}">${_("Mail Queues")}</a></li>
				% if c.user.is_superadmin:
				<li class="nav_item"><a href="${url('status-audit-logs')}">${_("Audit Logs")}</a></li>
				% endif
            </ul>
        </div>
    </div>
</div>
</%def>

<%def name="localscripts()">\
${h.javascript_link(h.media_url() + 'js/vendor/jquery.flot.min.js',
h.media_url() + 'js/vendor/jquery.flot.pie.min.js',
h.media_url() + 'js/vendor/jquery.flot.resize.min.js',
h.media_url() + 'js/baruwa/status.min.js')}
</%def>
<%inherit file="../base.html"/>
