#!/bin/bash
# -----------------------------------------------------------------
# Netfilter / GNULinux Network IPTables plugin for Pandora FMS
# (c) Sancho Lerena 2008-2009.
# This is an agent plugin, used only on local agents
# NOTE: This agent needs the system command 'bc' to calculate hex data
# -----------------------------------------------------------------
TEMP=/tmp/network.tmp
cat /proc/net/stat/ip_conntrack | tail -1 | tr "[:lower:]" "[:upper:]" > $TEMP
CT_ENTRIES_T=`cat $TEMP | awk '{ print $1 }'`
CT_ENTRIES=`echo "ibase=16; $CT_ENTRIES_T" | bc`
CT_NEW_T=`cat $TEMP | awk '{ print $3 }'`
CT_NEW=`echo "ibase=16; $CT_NEW_T" | bc`
CT_INVALID_T=`cat $TEMP | awk '{ print $4 }'`
CT_INVALID=`echo "ibase=16; $CT_INVALID_T" | bc`
rm $TEMP 2> /dev/null
CONTRACKFILE=/tmp/conntrack.pandora
cat /proc/net/ip_conntrack > $CONTRACKFILE 2> /dev/null
fw_con_established=`cat $CONTRACKFILE | grep ESTABLISH | wc -l`
fw_con_timewait=`cat $CONTRACKFILE | grep TIME_WAIT | wc -l`
fw_con_syn_wait=`cat $CONTRACKFILE | grep SYN_ | wc -l`
fw_con_fin_wait=`cat $CONTRACKFILE | grep FIN_WAIT | wc -l`
fw_con_unreplied=`cat $CONTRACKFILE | grep UNREPLIED | wc -l`
fw_enabled=`cat /proc/sys/net/ipv4/ip_forward`
rm $CONTRACKFILE 2> /dev/null
echo ""
echo "Conntrack Active Entries"
echo "generic_data"
echo "Get active entries in Netfilter conntrack session table"
echo "$CT_ENTRIES"
echo ""
echo ""
echo "Conntrack New"
echo "generic_data_inc"
echo "Get new connections in Netfilter conntrack session table"
echo "$CT_NEW"
echo ""
echo ""
echo "Conntrack Invalid"
echo "generic_data_inc"
echo "Get invalid entries in Netfilter conntrack session table"
echo "$CT_INVALID"
echo ""
echo ""
echo "fw_con_established"
echo "generic_data"
echo "Established connetions on Firewall"
echo "$fw_con_established"
echo ""
echo ""
echo "fw_con_timewait"
echo "generic_data"
echo "Established connections pending to timeout"
echo "$fw_con_timewait"
echo ""
echo ""
echo "fw_con_syn_wait"
echo "generic_data"
echo "Not-established connections, waiting to other side"
echo "$fw_con_syn_wait"
echo ""
echo ""
echo "fw_con_fin_wait"
echo "generic_data"
echo "Established connections waiting FIN on other side"
echo "$fw_con_fin_wait"
echo ""
echo ""
echo "fw_con_unreplied"
echo "generic_data"
echo "Unreplied connection attempts"
echo "$fw_con_unreplied"
echo ""
echo ""
echo "fw_enabled"
echo "generic_proc"
echo "Forwarding enabled"
echo "$fw_enabled"
echo ""