OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 |
| 3 import subprocess |
| 4 |
| 5 if __name__ == "__main__": |
| 6 process_output = subprocess.check_output(["netstat", "-nt"]) |
| 7 |
| 8 established = 0 |
| 9 opening = 0 |
| 10 closing = 0 |
| 11 for line in process_output.splitlines(): |
| 12 data = line.split() |
| 13 if len(data) < 6: |
| 14 continue |
| 15 |
| 16 status = data[5] |
| 17 if status == "ESTABLISHED": |
| 18 established += 1 |
| 19 elif status == "SYN_RECV": |
| 20 opening += 1 |
| 21 elif status in ("FIN_WAIT1", "FIN_WAIT2", "CLOSE_WAIT", "LAST_ACK", "CLOSING
"): |
| 22 closing += 1 |
| 23 |
| 24 status = "established %i opening %i closing %i" % (established, opening, closi
ng) |
| 25 |
| 26 perfdata = "established=%i opening=%i closing=%i" % (established, opening, clo
sing) |
| 27 |
| 28 output = "%s|%s" % (status, perfdata) |
| 29 |
| 30 print "OK - " + output |
OLD | NEW |