class TestPluginWithSocket(TestPluginBase):
    def setUp(self):
        self._main = x224.main
        self.nc = NetEcho(host='localhost')
        self.nc.start()

    def tearDown(self):
        self.nc.join()

    def test_bad_rsp_length(self):
        self.nc.echo = "BAD X224 LENGTH"  # not 11 nor 19 ..
        sys.argv = [sys.argv[0], '-H', 'localhost', '-p', str(self.nc.port)]
        self.do_tst(2, "^x224 RDP response of unexpected length \(15\)$")

    def test_bad_version(self):
        self.nc.echo = "A" * 11
        sys.argv = [sys.argv[0], '-H', 'localhost', '-p', str(self.nc.port)]
        self.do_tst(2, "Unexpected version-value")

    def test_bad_elements(self):
        self.nc.echo = "\x03" + "A" * 10
        sys.argv = [sys.argv[0], '-H', 'localhost', '-p', str(self.nc.port)]
        self.do_tst(2, "Unexpected element\(s\)")

    def test_good_connection(self):
        self.nc.echo = '\x03\x00\x00\x13\x0e\xd0\x00\x00\x124\x00\x02\x01\x08\x00\x02\x00\x00\x00'
        sys.argv = [sys.argv[0], '-H', 'localhost', '-p', str(self.nc.port)]
        self.do_tst(0, "^x224 OK.")
class TestPluginWithSocket(TestPluginBase):
    def setUp(self):
        self._main = x224.main
        self.nc = NetEcho(host="localhost")
        self.nc.start()

    def tearDown(self):
        self.nc.join()

    def test_bad_rsp_length(self):
        self.nc.echo = "BAD X224 LENGTH"  # not 11 nor 19 ..
        sys.argv = [sys.argv[0], "-H", "localhost", "-p", str(self.nc.port)]
        self.do_tst(2, "^x224 RDP response of unexpected length \(15\)$")

    def test_bad_version(self):
        self.nc.echo = "A" * 11
        sys.argv = [sys.argv[0], "-H", "localhost", "-p", str(self.nc.port)]
        self.do_tst(2, "Unexpected version-value")

    def test_bad_elements(self):
        self.nc.echo = "\x03" + "A" * 10
        sys.argv = [sys.argv[0], "-H", "localhost", "-p", str(self.nc.port)]
        self.do_tst(2, "Unexpected element\(s\)")

    def test_good_connection(self):
        self.nc.echo = "\x03\x00\x00\x13\x0e\xd0\x00\x00\x124\x00\x02\x01\x08\x00\x02\x00\x00\x00"
        sys.argv = [sys.argv[0], "-H", "localhost", "-p", str(self.nc.port)]
        self.do_tst(0, "^x224 OK.")
class TestPluginWithSocket(TestPluginBase):

    def setUp(self):
        self._main = graphite_api.main
        self.nc = NetEcho(host='localhost', port=8080)
        self.nc.start()

    def tearDown(self):
        self.nc.join()

    def test_default_delay(self):
        """Test test_default_delay :
        -v -u http://localhost:8080/graphite -t hst.svc.graph
        """
        self.nc.echo = """[{"target": "hst.svc.graph", "datapoints": [[null, 1], [%s, 2]]}]""" % '22'
        sys.argv = [sys.argv[0]]
        sys.argv.append('-M')
        sys.argv.append('-u')
        sys.argv.append('http://localhost:8080/graphite')
        sys.argv.append('-t')
        sys.argv.append('hst.svc.graph')
        self.do_tst(0, "^OK : Data found$")

    def test_bad_json(self):
        """Test test_bad_json :
        -v -u http://localhost:8080/graphite -t hst.svc.graph
        """
        self.nc.echo = """[{"target": "hst.svc.graph", "datapoints": [[null, 1], [%s, 2]]}]""" % 'None'
        sys.argv = [sys.argv[0]]
        sys.argv.append('-u')
        sys.argv.append('http://localhost:8080/graphite')
        sys.argv.append('-t')
        sys.argv.append('hst.svc.graph')
        self.do_tst(3, "UNKNOWN : JSON not decoded$")

    def test_no_data(self):
        """Test test_no_data :
        -v -u http://localhost:8080/graphite -t hst.svc.graph
        """
        self.nc.echo = """[{"target": "hst.svc.graph", "datapoints": [[null, 1], [%s, 2]]}]""" % 'null'
        sys.argv = [sys.argv[0]]
        sys.argv.append('-u')
        sys.argv.append('http://localhost:8080/graphite')
        sys.argv.append('-t')
        sys.argv.append('hst.svc.graph')
        self.do_tst(2, "CRITICAL : No data found$")
Example #4
0
class TestPluginWithSocket(TestPluginBase):
    def setUp(self):
        self._main = graphite_api.main
        self.nc = NetEcho(host='localhost', port=8080)
        self.nc.start()

    def tearDown(self):
        self.nc.join()

    def test_default_delay(self):
        """Test test_default_delay :
        -v -u http://localhost:8080/graphite -t hst.svc.graph
        """
        self.nc.echo = """[{"target": "hst.svc.graph", "datapoints": [[null, 1], [%s, 2]]}]""" % '22'
        sys.argv = [sys.argv[0]]
        sys.argv.append('-M')
        sys.argv.append('-u')
        sys.argv.append('http://localhost:8080/graphite')
        sys.argv.append('-t')
        sys.argv.append('hst.svc.graph')
        self.do_tst(0, "^OK : Data found$")

    def test_bad_json(self):
        """Test test_bad_json :
        -v -u http://localhost:8080/graphite -t hst.svc.graph
        """
        self.nc.echo = """[{"target": "hst.svc.graph", "datapoints": [[null, 1], [%s, 2]]}]""" % 'None'
        sys.argv = [sys.argv[0]]
        sys.argv.append('-u')
        sys.argv.append('http://localhost:8080/graphite')
        sys.argv.append('-t')
        sys.argv.append('hst.svc.graph')
        self.do_tst(3, "UNKNOWN : JSON not decoded$")

    def test_no_data(self):
        """Test test_no_data :
        -v -u http://localhost:8080/graphite -t hst.svc.graph
        """
        self.nc.echo = """[{"target": "hst.svc.graph", "datapoints": [[null, 1], [%s, 2]]}]""" % 'null'
        sys.argv = [sys.argv[0]]
        sys.argv.append('-u')
        sys.argv.append('http://localhost:8080/graphite')
        sys.argv.append('-t')
        sys.argv.append('hst.svc.graph')
        self.do_tst(2, "CRITICAL : No data found$")
Example #5
0
 def setUp(self):
     self._main = poller2livestatus.main
     self.nc = NetEcho(host='127.0.0.1', port=0)  # let it choose the port
     self.port_str = str(self.nc.port)
     self.nc.start()
Example #6
0
class TestPluginWithSocket(TestPluginBase):
    def setUp(self):
        self._main = poller2livestatus.main
        self.nc = NetEcho(host='127.0.0.1', port=0)  # let it choose the port
        self.port_str = str(self.nc.port)
        self.nc.start()

    def tearDown(self):
        self.nc.stop()
        self.nc.join()

    def test_connection_ok(self):
        """Test connection ok :
        -B localhost -P 50001 -H myhost -S myservice -p mypoller
        """
        now = int(time.time())
        self.nc.echo = 'myhost;myservice;%d;5' % now

        sys.argv = [sys.argv[0]]
        sys.argv.append('-B')
        sys.argv.append('127.0.0.1')
        sys.argv.append('-P')
        sys.argv.append(self.port_str)
        sys.argv.append('-H')
        sys.argv.append('myhost')
        sys.argv.append('-S')
        sys.argv.append('myservice')
        sys.argv.append('-p')
        sys.argv.append('mypoller')
        self.do_tst(0, "")


    def test_connection_ok_check(self):
        """Test connection ok check :
        -B 127.0.0.1 -P 50001 -H myhost -S myservice -p mypoller -C mybroker
        """
        now = int(time.time())
        self.nc.echo = 'myhost;myservice;%d;5' % now

        sys.argv = [sys.argv[0]]
        sys.argv.append('-B')
        sys.argv.append('127.0.0.1')
        sys.argv.append('-P')
        sys.argv.append(self.port_str)
        sys.argv.append('-H')
        sys.argv.append('myhost')
        sys.argv.append('-S')
        sys.argv.append('myservice')
        sys.argv.append('-p')
        sys.argv.append('mypoller')
        sys.argv.append('-C')
        sys.argv.append('mybroker')
        self.do_tst(0, "| delta=")

    def test_connection_warning(self):
        """Test connection warning
        -B 127.0.0.1 -H myhost -S myservice -p mypoller -w 60 -c 120
        """
        now = int(time.time()) - 65
        self.nc.echo = 'myhost;myservice;%d;5' % now

        sys.argv = [sys.argv[0]]
        sys.argv.append('-B')
        sys.argv.append('127.0.0.1')
        sys.argv.append('-P')
        sys.argv.append(self.port_str)
        sys.argv.append('-H')
        sys.argv.append('myhost')
        sys.argv.append('-S')
        sys.argv.append('myservice')
        sys.argv.append('-p')
        sys.argv.append('mypoller')
        sys.argv.append('-w')
        sys.argv.append('60')
        sys.argv.append('-c')
        sys.argv.append('120')
        self.do_tst(1, "# delta:6[0-9]")

    def test_connection_critical(self):
        """Test connection critical
        -B 127.0.0.1 -H myhost -p mypoller -w 60 -c 120
        """
        now = int(time.time()) - 155
        self.nc.echo = 'myhost;%d;5' % now

        sys.argv = [sys.argv[0]]
        sys.argv.append('-B')
        sys.argv.append('127.0.0.1')
        sys.argv.append('-P')
        sys.argv.append(self.port_str)
        sys.argv.append('-H')
        sys.argv.append('myhost')
        sys.argv.append('-p')
        sys.argv.append('mypoller')
        sys.argv.append('-w')
        sys.argv.append('60')
        sys.argv.append('-c')
        sys.argv.append('120')
        self.do_tst(2, "# delta:15[0-9]")
 def setUp(self):
     self._main = graphite_api.main
     self.nc = NetEcho(host='localhost', port=8080)
     self.nc.start()
 def setUp(self):
     self._main = x224.main
     self.nc = NetEcho(host='localhost')
     self.nc.start()
 def setUp(self):
     self._main = x224.main
     self.nc = NetEcho(host="localhost")
     self.nc.start()
Example #10
0
 def setUp(self):
     self._main = graphite_api.main
     self.nc = NetEcho(host='localhost', port=8080)
     self.nc.start()