@@ -0,0 +1,1051 @@
+#! /usr/bin/env python%0A# This is a Server Density netstat plugin%0A# Author: yaniv.aknin@audish.com%0A%0Aimport platform%0Aassert platform.system() == 'Linux', 'I ought to run in Linux'%0A%0Aimport os%0Afrom subprocess import Popen, PIPE%0A%0Aclass netstat(object):%0A    def __init__(self, agentConfig, checksLogger, rawConfig):%0A        self.agentConfig = agentConfig%0A        self.checksLogger = checksLogger%0A        self.rawConfig = rawConfig%0A%0A    def run(self):%0A        result = %7B%7D%0A        process = Popen('netstat -tn', shell=True, stdout=PIPE, preexec_fn=lambda: os.close(0))%0A        stdout, dummy_stderr = process.communicate()%0A        for line in stdout.splitlines()%5B2:%5D: # first two lines in linux netstat are headers%0A            proto, recvq, sendq, local, remote, state = line.split()%0A            if state not in result:%0A                result%5Bstate%5D = 0%0A            result%5Bstate%5D += 1%0A        return result%0A%0A%0Aif __name__ == '__main__':%0A    import logging%0A    logging.basicConfig()%0A    plugin = netstat(None, logging, dict(Main=dict()))%0A    print(plugin.run())%0A

add netstat connection state plugin