Added function that can find out which IP address interfaces on a computer has.

This commit is contained in:
Roland Hedberg
2013-09-02 15:43:30 +02:00
parent 452ec2c18a
commit 5d76d453a5

View File

@@ -3,6 +3,7 @@ import time
import traceback import traceback
import requests import requests
import sys import sys
import socket
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from saml2test.check import CRITICAL from saml2test.check import CRITICAL
@@ -32,45 +33,6 @@ class OperationError(Exception):
pass pass
# class Trace(object):
# def __init__(self):
# self.trace = []
# self.start = time.time()
#
# def request(self, msg):
# delta = time.time() - self.start
# self.trace.append("%f --> %s" % (delta, msg))
#
# def reply(self, msg):
# delta = time.time() - self.start
# self.trace.append("%f <-- %s" % (delta, msg))
#
# def info(self, msg, who="saml2client"):
# delta = time.time() - self.start
# self.trace.append("%f - INFO - [%s] %s" % (delta, who, msg))
#
# def error(self, msg, who="saml2client"):
# delta = time.time() - self.start
# self.trace.append("%f - ERROR - [%s] %s" % (delta, who, msg))
#
# def warning(self, msg, who="saml2client"):
# delta = time.time() - self.start
# self.trace.append("%f - WARNING - [%s] %s" % (delta, who, msg))
#
# def __str__(self):
# return "\n". join([t.encode("utf-8") for t in self.trace])
#
# def clear(self):
# self.trace = []
#
# def __getitem__(self, item):
# return self.trace[item]
#
# def next(self):
# for line in self.trace:
# yield line
class ContextFilter(logging.Filter): class ContextFilter(logging.Filter):
""" """
This is a filter which injects time laps information into the log. This is a filter which injects time laps information into the log.
@@ -128,3 +90,8 @@ def exception_trace(tag, exc, log=None):
_exc = "Exception: %s" % exc.message.encode("utf-8", "replace") _exc = "Exception: %s" % exc.message.encode("utf-8", "replace")
return {"status": CRITICAL, "message": _exc, "content": "".join(message)} return {"status": CRITICAL, "message": _exc, "content": "".join(message)}
def ip_addresses():
return [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2]
if not ip.startswith("127.")]