当前位置: 首页>>代码示例>>Python>>正文


Python assimevent.AssimEvent类代码示例

本文整理汇总了Python中assimevent.AssimEvent的典型用法代码示例。如果您正苦于以下问题:Python AssimEvent类的具体用法?Python AssimEvent怎么用?Python AssimEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AssimEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ioerror

 def ioerror(self, unusedevent):
     '''This function gets called when we get an I/O error writing to the FIFO.
     This is likely an EPIPE (broken pipe) error.
     '''
     unusedevent = unusedevent # Make pylint happy...
     if self.maxerrcount is not None and self.errcount > self.maxerrcount:
         AssimEvent.unregisterobserver(self)
开发者ID:borgified,项目名称:assimilation,代码行数:7,代码来源:assimeventobserver.py

示例2: test_automonitor_LSB_failures

 def test_automonitor_LSB_failures(self):
     AssimEvent.disable_all_observers()
     self.assertRaises(ValueError, LSBMonitoringRule, "neo4j-service", [])
     self.assertRaises(ValueError, LSBMonitoringRule, "neo4j-service", (("a.b.c", ")"),))
     self.assertRaises(ValueError, LSBMonitoringRule, "neo4j-service", ((1, 2, 3, 4, 5),))
     self.assertRaises(ValueError, LSBMonitoringRule, "neo4j-service", ((1,),))
     self.assertRaises(ValueError, LSBMonitoringRule, "neo4j-service", ((),))
开发者ID:Alan-R,项目名称:assimilation-persistent-events,代码行数:7,代码来源:cma_test.py

示例3: test_automonitor_strings_basic

    def test_automonitor_strings_basic(self):
        # Clean things out so we only see what we want to see...
        AssimEvent.disable_all_observers()
        ocf_string = '''{
#       comment
        "class":        "ocf",
        "type":         "neo4j",
        "provider":     "assimilation",
        "classconfig": [
            [null,      "@basename()",              "java$"],
            [null,      "$argv[-1]",                 "org\\.neo4j\\.server\\.Bootstrapper$"],
            ["PORT",    "serviceport",              "[0-9]+$"],
            ["NEOHOME", "@argequals(-Dneo4j.home)", "/.*"]
        ]
}'''
        ocf = MonitoringRule.ConstructFromString(ocf_string)
        self.assertTrue(isinstance(ocf, OCFMonitoringRule))
        lsb_string = '''{
#       comment
        "class":        "lsb",
        "type":         "neo4j",
        "classconfig": [
            ["@basename()",    "java$"],
            ["$argv[-1]",       "org\\.neo4j\\.server\\.Bootstrapper$"],
        ]
}'''
        lsb = MonitoringRule.ConstructFromString(lsb_string)
        self.assertTrue(isinstance(lsb, LSBMonitoringRule))
开发者ID:carrieao,项目名称:assimilation-official,代码行数:28,代码来源:cma_test.py

示例4: __init__

    def __init__(self, constraints):
        '''Initializer for AssimEventObserver class.

        Parameters:
        -----------
        constraints: dict-like *or* callable() returning bool
            A dict describing our desired events. The constraints in the dict are
            effectively ANDed together.  Each key is an attribute name in either
            the event itself or its associated object.  The value associated with
            each attribute is either a list or a scalar value or something
            implementing __contains__.  A scalar value implies that it *must* have exactly
            that value, otherwise it must be *in* the associated list/tuple/etc.

            This should be able to constrain the type of event we're looking at, the
            type of event-object we're looking at, and the domain of the event-object -
            and lots of other potentially useful things.

            See the "is_interesting" method below for implementation details...

            If 'constraints' is a callable (that is, callable(constraints) is True), then
            we will just call constraints(event) to see if the event is interesting to
            this observer. Whatever 'constraints' returns will be interpreted in a
            boolean context - so returning a bool would be a good idea...
        '''
        self.constraints = constraints
        AssimEvent.registerobserver(self)
开发者ID:JJediny,项目名称:assimilation-official,代码行数:26,代码来源:assimeventobserver.py

示例5: test_simple_init_bad

 def test_simple_init_bad(self):
     'Perform a few simple AssimEvent bad initializations'
     AssimEvent.enable_all_observers()
     AssimEvent.observers = []
     observer=DummyObserver()
     badobserver=BadObserver()
     AssimEvent.registerobserver(observer)
     self.assertRaises(ValueError, AssimEvent, 'first', 999)
     self.assertRaises(AttributeError, AssimEvent.registerobserver, badobserver)
开发者ID:Alan-R,项目名称:assimilation-persistent-events,代码行数:9,代码来源:assimevent_test.py

示例6: test_fork_exec_event

    def test_fork_exec_event(self):
        '''This test will create a fork/exec event observer script
        and then test to see if its getting invoked properly...
        '''
        AssimEvent.enable_all_observers()
        tmpdir = tempfile.mkdtemp('.d', 'testexec_')
        (fd, pathname) = tempfile.mkstemp('.out.txt')
        execscript = os.path.join(tmpdir, 'observer.sh')
        makescript(execscript, pathname)
        AssimEvent.observers = []
        observer=ForkExecObserver(scriptdir=tmpdir)
        dummyclient = ClientClass()
        dummyclient.fred='fred'
        dummyclient.sevenofnine='Annika'
        dummyclient.foo = {'foo': 'bar'}

        self.assertEqual(observer.listscripts(), [execscript,])
        AssimEvent.registerobserver(observer)
        AssimEvent(dummyclient, AssimEvent.CREATEOBJ)
        AssimEvent(dummyclient, AssimEvent.OBJUP, extrainfo={'origaddr': '10.10.10.254'})
        os.close(fd)
        expectedcontent=\
'''====START====
ARG1=create
ARG2=ClientClass
ASSIM_fred=fred
ASSIM_nodetype=ClientClass
ASSIM_sevenofnine=Annika
==== JSON START ====
{"associatedobject":{"foo":{"foo":"bar"},"fred":"fred","nodetype":"ClientClass","sevenofnine":"Annika"},"eventtype":0,"extrainfo":null}
==== JSON END ====
====END====
====START====
ARG1=up
ARG2=ClientClass
ASSIM_fred=fred
ASSIM_nodetype=ClientClass
ASSIM_origaddr=10.10.10.254
ASSIM_sevenofnine=Annika
==== JSON START ====
{"associatedobject":{"foo":{"foo":"bar"},"fred":"fred","nodetype":"ClientClass","sevenofnine":"Annika"},"eventtype":1,"extrainfo":{"origaddr":"10.10.10.254"}}
==== JSON END ====
====END====
'''
        TestAssimEvent.waitfor(pathname, expectedcontent)
        f=open(pathname, 'r')
        content=f.read()
        f.close()
        self.assertEqual(content, expectedcontent)
        os.unlink(execscript)
        os.unlink(pathname)
        os.rmdir(tmpdir)
开发者ID:Alan-R,项目名称:assimilation-persistent-events,代码行数:52,代码来源:assimevent_test.py

示例7: test_fork_exec_killchild

    def test_fork_exec_killchild(self):
        '''This test will create a fork/exec event observer script
        and then kill the child listener and verify that it is handled
        correctly.
        '''
        AssimEvent.enable_all_observers()
        tmpdir = tempfile.mkdtemp('.d', 'testexec_')
        (fd, pathname) = tempfile.mkstemp('.out.txt')
        execscript = os.path.join(tmpdir, 'observer.sh')
        makescript(execscript, pathname)
        AssimEvent.observers = []
        observer=ForkExecObserver(scriptdir=tmpdir)
        dummyclient = ClientClass()
        dummyclient.fred='fred'
        dummyclient.sevenofnine='Annika'
        dummyclient.foo = {'foo': 'bar'}
        AssimEvent.registerobserver(observer)
        try:
            os.kill(observer.childpid, signal.SIGKILL)
        except OSError:
            # "docker build" doesn't let us kill processes...
            # so we give up on this test and call it good...
            os.unlink(execscript)
            os.unlink(pathname)
            os.rmdir(tmpdir)
            return
        time.sleep(0.1)
        AssimEvent(dummyclient, AssimEvent.CREATEOBJ)
        # Death of our FIFO child will cause it to get respawned, and
        # message sent to new child.  No messages should be lost.
        expectedcontent=\
'''====START====
ARG1=create
ARG2=ClientClass
ASSIM_fred=fred
ASSIM_nodetype=ClientClass
ASSIM_sevenofnine=Annika
==== JSON START ====
{"associatedobject":{"foo":{"foo":"bar"},"fred":"fred","nodetype":"ClientClass","sevenofnine":"Annika"},"eventtype":0,"extrainfo":null}
==== JSON END ====
====END====
'''
        TestAssimEvent.waitfor(pathname, expectedcontent)
        f=open(pathname, 'r')
        content=f.read()
        f.close()
        self.assertEqual(content, expectedcontent)
        os.close(fd)
        os.unlink(execscript)
        os.unlink(pathname)
        os.rmdir(tmpdir)
开发者ID:Alan-R,项目名称:assimilation-persistent-events,代码行数:51,代码来源:assimevent_test.py

示例8: test_eof

 def test_eof(self):
     'Get EOF with empty input'
     if BuildListOnly: return
     if DEBUG:
         print >> sys.stderr, 'Running test_test_eof()'
     AssimEvent.disable_all_observers()
     framesets=[]
     io = TestIO(framesets, 0)
     CMAinit(io, cleanoutdb=True, debug=DEBUG)
     # just make sure it seems to do the right thing
     (foo, bar) = io.recvframesets()
     assert foo is None
     del io
     assert_no_dangling_Cclasses()
开发者ID:carrieao,项目名称:assimilation-official,代码行数:14,代码来源:cma_test.py

示例9: test_get1pkt

 def test_get1pkt(self):
     'Read a single packet'
     if BuildListOnly: return
     if DEBUG:
         print >> sys.stderr, 'Running test_test_eof()'
     AssimEvent.disable_all_observers()
     otherguy = pyNetAddr([1,2,3,4],)
     strframe1=pyCstringFrame(FrameTypes.CSTRINGVAL, "Hello, world.")
     fs = pyFrameSet(42)
     fs.append(strframe1)
     framesets=((otherguy, (strframe1,)),)
     io = TestIO(framesets, 0)
     CMAinit(io, cleanoutdb=True, debug=DEBUG)
     gottenfs = io.recvframesets()
     self.assertEqual(len(gottenfs), 2)
     self.assertEqual(gottenfs, framesets[0])
     gottenfs = io.recvframesets()
     self.assertEqual(len(gottenfs), 2)
     assert gottenfs[0] is None
     io.cleanio()
     del io
开发者ID:carrieao,项目名称:assimilation-official,代码行数:21,代码来源:cma_test.py

示例10: __init__

    def __init__(self, constraints):
        '''Initializer for AssimEventObserver class.

        Parameters:
        -----------
        constraints: dict
            A dict describing our desired events. The constraints in the dict are
            effectively ANDed together.  Each key is an attribute name in either
            the event itself or its associated object.  The value associated with
            each attribute is either a list or a scalar value.  A list implies that
            any one of those values is acceptable.  A scalar value implies that it
            *must* have that value.

            This should be able to constrain the type of event we're looking at, the
            type of event-object we're looking at, and the domain of the event-object -
            and lots of other potentially useful things.

            See the "is_interesting" method below for implementation details...
        '''
        self.constraints = constraints
        AssimEvent.registerobserver(self)
开发者ID:borgified,项目名称:assimilation,代码行数:21,代码来源:assimeventobserver.py

示例11: test_echo1pkt

 def test_echo1pkt(self):
     'Read a packet and write it back out'
     if BuildListOnly: return
     if DEBUG:
         print >> sys.stderr, 'Running test_echo1pkt()'
     AssimEvent.disable_all_observers()
     strframe1=pyCstringFrame(FrameTypes.CSTRINGVAL, "Hello, world.")
     fs = pyFrameSet(42)
     fs.append(strframe1)
     otherguy = pyNetAddr([1,2,3,4],)
     framesets=((otherguy, (strframe1,)),)
     io = TestIO(framesets, 0)
     CMAinit(io, cleanoutdb=True, debug=DEBUG)
     fslist = io.recvframesets()     # read in a packet
     self.assertEqual(len(fslist), 2)
     self.assertEqual(fslist, framesets[0])
     io.sendframesets(fslist[0], fslist[1])  # echo it back out
     self.assertEqual(len(io.packetswritten), len(framesets))
     gottenfs = io.recvframesets()
     self.assertEqual(len(gottenfs), 2)
     assert gottenfs[0] is None
     io.cleanio()
     del io
开发者ID:carrieao,项目名称:assimilation-official,代码行数:23,代码来源:cma_test.py

示例12: test_simple_init_good

 def test_simple_init_good(self):
     'Perform a few simple AssimEvent good initializations'
     AssimEvent.enable_all_observers()
     AssimEvent.observers = []
     observer=DummyObserver()
     AssimEvent.registerobserver(observer)
     event1 = AssimEvent('first', AssimEvent.CREATEOBJ)
     self.assertEqual(len(observer.events), 1)
     self.assertTrue(observer.events[0], event1)
     self.assertEqual(AssimEvent.unregisterobserver(observer), True)
     event2 = AssimEvent('second', AssimEvent.CREATEOBJ)
     self.assertEqual(len(observer.events), 1)
     self.assertTrue(observer.events[0], event1)
     AssimEvent.registerobserver(observer)
     event3 = AssimEvent('third', AssimEvent.CREATEOBJ)
     self.assertEqual(len(observer.events), 2)
     self.assertTrue(observer.events[0], event3)
开发者ID:Alan-R,项目名称:assimilation-persistent-events,代码行数:17,代码来源:assimevent_test.py

示例13: disabled

if t2 < 10: t2 = 10
t3 = t2

if not DoAudit:
    print >> sys.stderr, 'WARNING: Audits suppressed.'
if not doHBDEAD:
    print >> sys.stderr, 'WARNING: Server death tests disabled.'
if not CheckForDanglingClasses:
    print >> sys.stderr, 'WARNING: Memory Leak Detection disabled.'
elif not AssertOnDanglingClasses:
    print >> sys.stderr, 'WARNING: Memory Leak assertions disabled (detection still enabled).'


#gc.set_threshold(t1, t2, t3)

AssimEvent.disable_all_observers()

def assert_no_dangling_Cclasses(doassert=None):
    global CheckForDanglingClasses
    global WorstDanglingCount
    sys._clear_type_cache()
    if doassert is None:
        doassert = AssertOnDanglingClasses
    CMAinit.uninit()
    gc.collect()    # For good measure...
    count =  proj_class_live_object_count()
    #print >>sys.stderr, "CHECKING FOR DANGLING CLASSES (%d)..." % count
    # Avoid cluttering the output up with redundant messages...
    if count > WorstDanglingCount and CheckForDanglingClasses:
        WorstDanglingCount = count
        if doassert:
开发者ID:carrieao,项目名称:assimilation-official,代码行数:31,代码来源:cma_test.py

示例14: test_startup

    def test_startup(self):
        '''A semi-interesting test: We send a STARTUP message and get back a
        SETCONFIG message with lots of good stuff in it.
        and for good measure, we also send along some discovery packets.
        '''
        if BuildListOnly: return
        if DEBUG:
            print >> sys.stderr, 'Running test_startup()'
        AssimEvent.disable_all_observers()
        from dispatchtarget import DispatchTarget
        droneid = 1
        droneip = droneipaddress(droneid)
        designation = dronedesignation(droneid)
        designationframe=pyCstringFrame(FrameTypes.HOSTNAME, designation)
        dronediscovery=hostdiscoveryinfo(droneid)
        discoveryframe=pyCstringFrame(FrameTypes.JSDISCOVER, dronediscovery)
        fs = pyFrameSet(FrameSetTypes.STARTUP)
        fs.append(designationframe)
        fs.append(discoveryframe)

        fs2 = pyFrameSet(FrameSetTypes.JSDISCOVERY)
        osdiscovery=pyCstringFrame(FrameTypes.JSDISCOVER, self.OS_DISCOVERY)
        fs2.append(osdiscovery)
        fs3 = pyFrameSet(FrameSetTypes.JSDISCOVERY)
        ulimitdiscovery=pyCstringFrame(FrameTypes.JSDISCOVER, self.ULIMIT_DISCOVERY)
        fs3.append(ulimitdiscovery)
        fsin = ((droneip, (fs,)), (droneip, (fs2,)), (droneip, (fs3,)))
        io = TestIO(fsin,0)
        #print >> sys.stderr, 'CMAinit: %s' % str(CMAinit)
        #print >> sys.stderr, 'CMAinit.__init__: %s' % str(CMAinit.__init__)
        OurAddr = pyNetAddr((127,0,0,1),1984)
        configinit = geninitconfig(OurAddr)
        config = pyConfigContext(init=configinit)
        io.config = config
        CMAinit(io, cleanoutdb=True, debug=DEBUG)
        CMAdb.io.config = config
        assimcli_check('loadqueries')
        disp = MessageDispatcher(DispatchTarget.dispatchtable, encryption_required=False)
        listener = PacketListener(config, disp, io=io, encryption_required=False)
        io.mainloop = listener.mainloop
        TestIO.mainloop = listener.mainloop
        # We send the CMA an intial STARTUP packet
        listener.listen()
        # Let's see what happened...
        #print >> sys.stderr, ('READ: %s' % io.packetsread)
        #print >> sys.stderr, ('WRITTEN: %s' % len(io.packetswritten))
        #print >> sys.stderr, ('PACKETS WRITTEN: %s' % str(io.packetswritten))

        self.assertEqual(len(io.packetswritten), 2) # Did we send out four packets?
                            # Note that this change over time
                            # As we change discovery...
        self.assertEqual(io.packetsread, 3) # Did we read 3 packets?
        AUDITS().auditSETCONFIG(io.packetswritten[0], droneid, configinit)
        assimcli_check("query allips", 1)
        assimcli_check("query allservers", 1)
        assimcli_check("query findip %s" % str(droneip), 1)
        assimcli_check("query shutdown", 0)
        assimcli_check("query crashed", 0)
        assimcli_check("query unknownips", 0)
        CMAdb.io.config = config
        Drones = CMAdb.store.load_cypher_nodes("START n=node:Drone('*:*') RETURN n", Drone)
        Drones = [drone for drone in Drones]
        for drone in Drones:
            self.check_discovery(drone, (dronediscovery, self.OS_DISCOVERY, self.ULIMIT_DISCOVERY))
        self.assertEqual(len(Drones), 1) # Should only be one drone
        io.config = None
        io.cleanio()
        del io
        del ulimitdiscovery, osdiscovery, Drones
        DispatchTarget.dispatchtable = {}
        del DispatchTarget
开发者ID:carrieao,项目名称:assimilation-official,代码行数:71,代码来源:cma_test.py

示例15: test_automonitor_functions

    def test_automonitor_functions(self):
        AssimEvent.disable_all_observers()
        MonitoringRule.monitor_objects = {'service': {}, 'host':{}}
        drone = FakeDrone({
                'data': {
                        'ocf': {
                            'assimilation/neo4j',
                        },
                        'lsb': {
                            'bacula',
                        },
                    }
                })
        ocf_string = '''{
        "class":        "ocf", "type":         "neo4j", "provider":     "assimilation",
        "classconfig": [
            ["classpath",   "@flagvalue(-cp)"],
            ["ipaddr",      "@serviceip($procinfo.listenaddrs)"],
            ["port",        "@serviceport()",   "[0-9]+$"]
        ]
        }'''
        ssh_json = '''{
          "exe": "/usr/sbin/sshd",
          "argv": [ "/usr/sbin/sshd", "-D" ],
          "uid": "root",
          "gid": "root",
          "cwd": "/",
          "listenaddrs": {
            "0.0.0.0:22": {
              "proto": "tcp",
              "addr": "0.0.0.0",
              "port": 22
            },
            ":::22": {
              "proto": "tcp6",
              "addr": "::",
              "port": 22
            }
          }
        }'''
        neo4j_json = '''{
          "exe": "/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java",
          "argv": [ "/usr/bin/java", "-cp", "/var/lib/neo4j/lib/concurrentlinkedhashmap-lru-1.3.1.jar: ...", "-server", "-XX:+DisableExplicitGC", "-Dorg.neo4j.server.properties=conf/neo4
    j-server.properties", "-Djava.util.logging.config.file=conf/logging.properties", "-Dlog4j.configuration=file:conf/log4j.properties", "-XX:
    +UseConcMarkSweepGC", "-XX:+CMSClassUnloadingEnabled", "-Dneo4j.home=/var/lib/neo4j", "-Dneo4j.instance=/var/lib/neo4j", "-Dfile.encoding=
    UTF-8", "org.neo4j.server.Bootstrapper" ],
          "uid": "neo4j",
          "gid": "neo4j",
          "cwd": "/var/lib/neo4j",
          "listenaddrs": {
            ":::1337": {
              "proto": "tcp6",
              "addr": "::",
              "port": 1337
            },
            ":::39185": {
              "proto": "tcp6",
              "addr": "::",
              "port": 39185
            }
          }
        }'''
        bacula_json = '''{
      "exe": "/usr/sbin/bacula-dir",
      "argv": [ "/usr/sbin/bacula-dir", "-c", "/etc/bacula/bacula-dir.conf", "-u", "bacula", "-g", "bacula" ],
      "uid": "bacula",
      "gid": "bacula",
      "cwd": "/",
      "listenaddrs": {
        "10.10.10.5:9101": {
          "proto": "tcp",
          "addr": "10.10.10.5",
          "port": 9101
        }
      }
    }'''
        MonitoringRule.ConstructFromString(ocf_string)
        neoargs = pyConfigContext(neo4j_json)['argv']
        testnode = ProcessNode('global', 'foofred', 'fred', '/usr/bin/java', neoargs
        ,   'root', 'root', '/', roles=(CMAconsts.ROLE_server,))

        testnode.procinfo = neo4j_json
        context = ExpressionContext((testnode, drone))
        (prio, match) = MonitoringRule.findbestmatch(context)
        self.assertEqual(prio, MonitoringRule.HIGHPRIOMATCH)
        self.assertEqual(match['arglist']['ipaddr'], '::1')
        self.assertEqual(match['arglist']['port'], '1337')

        testnode.procinfo = ssh_json
        context = ExpressionContext((testnode, drone))
        (prio, match) = MonitoringRule.findbestmatch(context)
        self.assertEqual(prio, MonitoringRule.HIGHPRIOMATCH)
        self.assertEqual(match['arglist']['port'], '22')
        self.assertEqual(match['arglist']['ipaddr'], '127.0.0.1')

        testnode.procinfo = bacula_json
        context = ExpressionContext((testnode, drone))
        (prio, match) = MonitoringRule.findbestmatch(context)
        self.assertEqual(prio, MonitoringRule.HIGHPRIOMATCH)
        self.assertEqual(match['arglist']['port'], '9101')
#.........这里部分代码省略.........
开发者ID:carrieao,项目名称:assimilation-official,代码行数:101,代码来源:cma_test.py


注:本文中的assimevent.AssimEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。