Files
scripts-conlxsyslog03/rancid/dev_port_overview/create_output.sh
conetadm 5718e70f15 init
2024-11-14 21:11:06 +01:00

280 lines
12 KiB
Bash
Executable File

#!/bin/bash
OUTPUT="result.html"
cd /scripts/rancid/dev_port_overview/ || exit
echo "<html>
<head>
<style>
table, td {
border: 1px solid black;
border-collapse: collapse;
text-align: center;
}
.tdSpacer {
border-top: 1px solid white;
border-bottom: 1px solid white;
width: 3px;
}
.tdTopLeftCorner {
border: 1px solid white;
border-bottom: 1px solid black;
}
.tdNoBorder {
border: 1px solid white;
}
</style>
</head>
<body>
<h1>Device and Port Report</h1>
<h2>Locations</h2>" > $OUTPUT
echo 'select count(distinct location) as "Locations" from devices_locations;' > select.sql
OUT1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUT2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo " <table>
<tr>
<td class=tdTopLeftCorner></td>
<td class=tdSpacer rowspan=3></td>
<td>via snmp</td>
</tr>
<tr>
<td>RZ</td>
<td>$OUT1</td>
</tr>
<!--
<tr>
<td>FLW</td>
<td>$OUT2</td>
</tr>
-->
</table>" >> $OUTPUT
echo " <h2>Devices</h2>" >> $OUTPUT
echo 'select count(*) as "Network devices (SW/RTR/DWDM)" from devices where type="network";' > select.sql
OUTa1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTa2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo 'select count(*) as "Firewalls (inc Cluster)" from devices where type="firewall";' > select.sql
OUTb1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTb2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo 'select count(distinct hostname) as "Firewall Cluster" from devices t1 inner join status t2 on t1.device_id = t2.device_id where t1.type="firewall" and t2.status_descr like "Failover%";' > select.sql
OUTc1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTc2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo 'select count(*) as "Wireless devices" from devices where type="wireless";' > select.sql
OUTd1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTd2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo 'select count(distinct device_id) as "FC Devices" from ports where ifOperStatus="up" and ifType="fibreChannel";' > select.sql
OUTe1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTe2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo " <table border=0>
<tr>
<td class=tdTopLeftCorner></td>
<td class=tdSpacer rowspan=3></td>
<td>SW/RTR/DWDM</td>
<td class=tdSpacer rowspan=3></td>
<td>Firewalls (inc Cluster)</td>
<td>Firewall Cluster</td>
<td class=tdSpacer rowspan=3></td>
<td>Wireless</td>
<td class=tdSpacer rowspan=3></td>
<td>FibreChannel</td>
</tr>
<tr>
<td>RZ</td>
<td>$OUTa1</td>
<td>$OUTb1</td>
<td>$OUTc1</td>
<td>$OUTd1</td>
<td>$OUTe1</td>
</tr>
<!---
<tr>
<td>FLW</td>
<td>$OUTa2</td>
<td>$OUTb2</td>
<td>$OUTc2</td>
<td>$OUTd2</td>
<td>$OUTe2</td>
</tr>
-->
</table>" >> $OUTPUT
echo " <h2>Ports</h2>" >> $OUTPUT
echo 'select count(*) as "All Ports" from ports where deleted="0";' > select.sql
OUTa1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTa2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo 'select count(*) as "active FC Ports" from ports where ifOperStatus="up" and ifType="fibreChannel" and port_label_base="fc" and deleted="0";' > select.sql
OUTb1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTb2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo 'select count(*) as "non-active FC Ports" from ports where ifOperStatus="down" and ifType="fibreChannel" and port_label_base="fc" and deleted="0";' > select.sql
OUTc1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTc2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo 'select count(*) as "active 4G FC Ports" from ports where ifOperStatus="up" and ifType="fibreChannel" and port_label_base="fc" and ifspeed="4000000000" and deleted="0";' > select.sql
OUTd1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTd2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo 'select count(*) as "non-active 4G FC Ports" from ports where ifOperStatus="down" and ifType="fibreChannel" and port_label_base="fc" and ifspeed="4000000000" and deleted="0";' > select.sql
OUTe1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTe2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo 'select count(*) as "active 8G FC Ports" from ports where ifOperStatus="up" and ifType="fibreChannel" and port_label_base="fc" and ifspeed="8000000000" and deleted="0";' > select.sql
OUTf1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTf2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo 'select count(*) as "non-active 8G FC Ports" from ports where ifOperStatus="down" and ifType="fibreChannel" and port_label_base="fc" and ifspeed="8000000000" and deleted="0";' > select.sql
OUTg1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTg2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo 'select count(*) as "active 16G FC Ports"from ports where ifOperStatus="up" and ifType="fibreChannel" and port_label_base="fc" and ifspeed="16000000000" and deleted="0";' > select.sql
OUTh1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTh2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo 'select count(*) as "non-active 16G FC Ports"from ports where ifOperStatus="down" and ifType="fibreChannel" and port_label_base="fc" and ifspeed="16000000000" and deleted="0";' > select.sql
OUTi1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTi2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo 'select count(*) as "active Ethernet Ports" from ports where ifOperStatus="up" and ifType="ethernetCsmacd" and deleted="0";' > select.sql
OUTj1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTj2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo 'select count(*) as "non-active Ethernet Ports" from ports where ifOperStatus="down" and ifType="ethernetCsmacd" and deleted="0";' > select.sql
OUTk1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTk2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo 'select count(*) as "active Gigabit Ethernet Ports" from ports where ifOperStatus="up" and ifType="ethernetCsmacd" and ifspeed="1000000000" and deleted="0";' > select.sql
OUTl1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTl2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo 'select count(*) as "non-active Gigabit Ethernet Ports" from ports where ifOperStatus="down" and ifType="ethernetCsmacd" and ifspeed="1000000000" and deleted="0";' > select.sql
OUTm1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTm2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo 'select count(*) as "active 10Gigabit Ethernet Ports" from ports where ifOperStatus="up" and ifType="ethernetCsmacd" and ifspeed="10000000000" and deleted="0";' > select.sql
OUTn1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTn2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo 'select count(*) as "non-active 10Gigabit Ethernet Ports" from ports where ifOperStatus="down" and ifType="ethernetCsmacd" and ifspeed="10000000000" and deleted="0";' > select.sql
OUTo1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTo2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo " <table>
<tr>
<td rowspan=2 class=tdTopLeftCorner></td>
<td rowspan=4 class=tdSpacer></td>
<td rowspan=2>All Ports</td>
<td rowspan=4 class=tdSpacer></td>
<td colspan=8>FibreChannel</td>
<td rowspan=4 class=tdSpacer></td>
<td colspan=8>Ethernet</td>
</tr>
<tr>
<td>active FC</td>
<td>non-active FC</td>
<td>active 4G FC</td>
<td>non-active 4G</td>
<td>active 8G FC</td>
<td>non-active 8G</td>
<td>active 16G FC</td>
<td>non-active 16G</td>
<td>active Ethernet</td>
<td>non-active Ethernet</td>
<td>active Gigabit</td>
<td>non-active Gigabit</td>
<td>active 10Gigabit</td>
<td>non-active 10Gigabit</td>
</tr>
<tr>
<td>RZ</td>
<td>$OUTa1</td>
<td>$OUTb1</td>
<td>$OUTc1</td>
<td>$OUTd1</td>
<td>$OUTe1</td>
<td>$OUTf1</td>
<td>$OUTg1</td>
<td>$OUTh1</td>
<td>$OUTi1</td>
<td>$OUTj1</td>
<td>$OUTk1</td>
<td>$OUTl1</td>
<td>$OUTm1</td>
<td>$OUTn1</td>
<td>$OUTo1</td>
</tr>
<!--
<tr>
<td>FLW</td>
<td>$OUTa2</td>
<td>$OUTb2</td>
<td>$OUTc2</td>
<td>$OUTd2</td>
<td>$OUTe2</td>
<td>$OUTf2</td>
<td>$OUTg2</td>
<td>$OUTh2</td>
<td>$OUTi2</td>
<td>$OUTj2</td>
<td>$OUTk2</td>
<td>$OUTl2</td>
<td>$OUTm2</td>
<td>$OUTn2</td>
<td>$OUTo2</td>
</tr>
-->
</table>" >> $OUTPUT
echo " <h2>IPSec</h2>" >> $OUTPUT
echo 'select count(distinct local_addr) as "Devices (FW/RTR) with Tunnels" from ipsec_tunnels where tunnel_status="active" and tunnel_deleted="0";' > select.sql
OUTa1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTa2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo 'select count(distinct peer_addr) as "Remote Firewalls" from ipsec_tunnels where tunnel_status="active" and tunnel_deleted="0";' > select.sql
OUTb1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTb2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo 'select count(*) as "active IPSec SAs" from ipsec_tunnels where tunnel_status="active" and tunnel_deleted="0";' > select.sql
OUTc1=$(mysql -u observium -pobservium -D observium < select.sql | tail -n1)
#OUTc2=$(mysql -h 10.140.8.100 -u observium -pobservium -D observium < select.sql | tail -n1)
echo " <table>
<tr>
<td class=tdTopLeftCorner></td>
<td class=tdSpacer rowspan=3></td>
<td>Devices (FW/RTR) with Tunnels</td>
<td class=tdSpacer rowspan=3></td>
<td>Remote Firewalls</td>
<td class=tdSpacer rowspan=3></td>
<td>active IPSec SAs</td>
</tr>
<tr>
<td>RZ</td>
<td>$OUTa1</td>
<td>$OUTb1</td>
<td>$OUTc1</td>
</tr>
<!--
<tr>
<td>FLW</td>
<td>$OUTa2</td>
<td>$OUTb2</td>
<td>$OUTc2</td>
</tr>
-->
</table>
</body>
</html>" >> $OUTPUT
rm select.sql