Exemplo n.º 1
0
os.chdir(os.path.dirname(os.path.abspath(__file__)))

urls = (r'/', 'Index', r'/dashboard', 'Dashboard', r'/sensor', 'Sensor',
        r'/search', 'Search', r'/sensor_state', 'SensorState', r'/timeline',
        'Timeline', r'/objsearch', 'ObjSearch', r'/obj', 'ObjViewer',
        r'/lastevents', 'LastEvents', r'/event', 'EventView', r'/hostobjects',
        'HostObjects', r'/detects_data', 'JsonDetects', r'/detects',
        'ViewDetects', r'/detect', 'ViewDetect')

web.config.debug = False
app = web.application(urls, globals())

render = web.template.render('templates',
                             base='base',
                             globals={
                                 'json': json,
                                 'tsToTime': tsToTime
                             })

if len(sys.argv) < 2:
    print("Usage: python app.py beach_config [listen_port]")
    sys.exit()

beach = Beach(sys.argv[1], realm='hcp')
del (sys.argv[1])
model = beach.getActorHandle('models',
                             nRetries=3,
                             timeout=30,
                             ident='lc/0bf01f7e-62bd-4cc4-9fec-4c52e82eb903')

app.run()
Exemplo n.º 2
0
class BEAdmin(object):
    token = None

    def __init__(self, beach_config, token, timeout=1000 * 10):
        self.token = token
        self.beach = Beach(beach_config, realm='hcp')
        self.vHandle = self.beach.getActorHandle(
            'c2/admin/1.0',
            ident='cli/955f6e63-9119-4ba6-a969-84b38bfbcc05',
            timeout=timeout,
            nRetries=3)

    def _query(self, cmd, data={}):
        data['token'] = self.token
        response = self.vHandle.request(cmd, data)
        return response

    def testConnection(self):
        return self._query('ping')

    def hcp_getAgentStates(self, aid=None, hostname=None):
        filters = {}
        if aid != None:
            filters['agent_id'] = aid
        if hostname != None:
            filters['hostname'] = hostname
        return self._query('hcp.get_agent_states', filters)

    def hcp_getEnrollmentRules(self):
        return self._query('hcp.get_enrollment_rules')

    def hcp_addEnrollmentRule(self, mask, externalIp, internalIp, newOrg,
                              newSubnet, hostname):
        return self._query(
            'hcp.add_enrollment_rule', {
                'mask': mask,
                'external_ip': externalIp,
                'internal_ip': internalIp,
                'new_org': newOrg,
                'new_subnet': newSubnet,
                'hostname': hostname
            })

    def hcp_delEnrollmentRule(self, mask, externalIp, internalIp, hostname):
        return self._query(
            'hcp.del_enrollment_rule', {
                'mask': mask,
                'external_ip': externalIp,
                'internal_ip': internalIp,
                'hostname': hostname
            })

    def hcp_getTaskings(self):
        return self._query('hcp.get_taskings')

    def hcp_addTasking(self, mask, moduleId, hashStr):
        return self._query('hcp.add_tasking', {
            'mask': mask,
            'module_id': int(moduleId),
            'hash': hashStr
        })

    def hcp_delTasking(self, mask, moduleId, hashStr):
        return self._query('hcp.remove_tasking', {
            'mask': mask,
            'module_id': int(moduleId),
            'hash': hashStr
        })

    def hcp_getModules(self):
        return self._query('hcp.get_modules')

    def hcp_addModule(self, moduleId, binary, signature, description):
        return self._query(
            'hcp.add_module', {
                'module_id': moduleId,
                'bin': binary,
                'signature': signature,
                'hash': hashlib.sha256(binary).hexdigest(),
                'description': description
            })

    def hcp_delModule(self, moduleId, hashStr):
        return self._query('hcp.remove_module', {
            'module_id': moduleId,
            'hash': hashStr
        })

    def hcp_relocAgent(self, agentid, newOrg, newSubnet):
        return self._query('hcp.reloc_agent', {
            'agentid': agentid,
            'new_org': newOrg,
            'new_subnet': newSubnet
        })

    def hcp_getRelocations(self):
        return self._query('hcp.get_relocations')

    def hbs_getProfiles(self):
        return self._query('hbs.get_profiles')

    def hbs_addProfile(self, mask, config):
        return self._query('hbs.set_profile', {
            'mask': mask,
            'module_configs': config
        })

    def hbs_delProfile(self, mask):
        return self._query('hbs.del_profile', {'mask': mask})

    def hbs_taskAgent(self,
                      toAgent,
                      task,
                      key,
                      id,
                      expiry=None,
                      investigationId=None):
        # Make sure it's a valid agentid
        a = AgentId(toAgent)
        if not a.isValid:
            return None
        if not type(task) is rSequence:
            return None
        s = Signing(key)
        r = rpcm(isHumanReadable=True, isDebug=True)

        tags = Symbols()

        if investigationId is not None and '' != investigationId:
            task.addStringA(tags.hbs.INVESTIGATION_ID, investigationId)

        toSign = (rSequence().addSequence(
            tags.base.HCP_ID,
            rSequence().addInt8(tags.base.HCP_ID_ORG, a.org).addInt8(
                tags.base.HCP_ID_SUBNET,
                a.subnet).addInt32(tags.base.HCP_ID_UNIQUE, a.unique).addInt8(
                    tags.base.HCP_ID_PLATFORM, a.platform).addInt8(
                        tags.base.HCP_ID_CONFIG, a.config)).addSequence(
                            tags.hbs.NOTIFICATION,
                            task).addInt32(tags.hbs.NOTIFICATION_ID, id))
        if None != expiry:
            toSign.addTimestamp(tags.base.EXPIRY, int(expiry))
        toSign = r.serialise(toSign)
        sig = s.sign(toSign)

        final = r.serialise(rSequence().addBuffer(
            tags.base.BINARY, toSign).addBuffer(tags.base.SIGNATURE, sig))

        return self._query('hbs.task_agent', {
            'task': final,
            'agentid': str(a),
            'expiry': expiry
        })
Exemplo n.º 3
0
class BEAdmin(object):
    token = None

    def __init__(self, beach_config, token, timeout=1000 * 10):
        self.token = token
        self.empty_uuid = uuid.UUID(bytes="\x00" * 16)
        self.beach = Beach(beach_config, realm='hcp')
        self.vHandle = self.beach.getActorHandle(
            'c2/admin/1.0',
            ident='cli/955f6e63-9119-4ba6-a969-84b38bfbcc05',
            timeout=timeout,
            nRetries=3)

    def _query(self, cmd, data={}):
        data['token'] = self.token
        response = self.vHandle.request(cmd, data)
        return response

    def testConnection(self):
        return self._query('ping')

    def hcp_getAgentStates(self, aid=None, hostname=None):
        filters = {}
        if aid is not None:
            filters['aid'] = aid
        if hostname is not None:
            filters['hostname'] = hostname
        return self._query('hcp.get_agent_states', filters)

    def hcp_getTaskings(self, oid=None):
        return self._query('hcp.get_taskings', {'oid': oid})

    def hcp_addTasking(self, mask, moduleId, hashStr):
        return self._query('hcp.add_tasking', {
            'mask': mask,
            'module_id': int(moduleId),
            'hash': hashStr
        })

    def hcp_delTasking(self, mask, moduleId):
        return self._query('hcp.remove_tasking', {
            'mask': mask,
            'module_id': int(moduleId)
        })

    def hcp_getModules(self):
        return self._query('hcp.get_modules')

    def hcp_addModule(self, moduleId, binary, signature, description):
        return self._query(
            'hcp.add_module', {
                'module_id': moduleId,
                'bin': binary,
                'signature': signature,
                'hash': hashlib.sha256(binary).hexdigest(),
                'description': description
            })

    def hcp_delModule(self, moduleId, hashStr):
        return self._query('hcp.remove_module', {
            'module_id': moduleId,
            'hash': hashStr
        })

    def hcp_getInstallers(self,
                          oid=None,
                          iid=None,
                          hash=None,
                          withContent=False):
        return self._query('hcp.get_installers', {
            'with_content': withContent,
            'oid': oid,
            'iid': iid,
            'hash': hash
        })

    def hcp_addInstaller(self, oid, iid, description, installer):
        return self._query(
            'hcp.add_installer', {
                'oid': oid,
                'iid': iid,
                'description': description,
                'installer': installer
            })

    def hcp_delInstaller(self, oid, iid, hash):
        return self._query('hcp.remove_installer', {
            'oid': oid,
            'iid': iid,
            'hash': hash
        })

    def hcp_getWhitelist(self, oid=None, iid=None):
        return self._query('hcp.get_whitelist', {'oid': oid, 'iid': iid})

    def hcp_addWhitelist(self, oid, iid, bootstrap):
        return self._query('hcp.add_whitelist', {
            'oid': oid,
            'iid': iid,
            'bootstrap': bootstrap
        })

    def hcp_delWhitelist(self, oid, iid):
        return self._query('hcp.remove_whitelist', {'oid': oid, 'iid': iid})

    def hbs_getProfiles(self, oid=[]):
        return self._query('hbs.get_profiles', {'oid': oid})

    def hbs_addProfile(self, mask, config, tag):
        return self._query('hbs.set_profile', {
            'mask': mask,
            'module_configs': config,
            'tag': tag
        })

    def hbs_delProfile(self, mask):
        return self._query('hbs.del_profile', {'mask': mask})

    def hbs_taskAgent(self,
                      toAgent,
                      task,
                      key,
                      id,
                      expiry=None,
                      investigationId=None):
        # Make sure it's a valid agentid
        a = AgentId(toAgent)
        if not type(task) is rSequence:
            return None
        s = Signing(key)
        r = rpcm(isHumanReadable=True, isDebug=True)

        tags = Symbols()

        if investigationId is not None and '' != investigationId:
            task.addStringA(tags.hbs.INVESTIGATION_ID, investigationId)

        toSign = (rSequence().addSequence(
            tags.base.HCP_IDENT,
            rSequence().addBuffer(
                tags.base.HCP_SENSOR_ID,
                (a.sensor_id if a.sensor_id is not None
                 else self.empty_uuid).bytes).addBuffer(
                     tags.base.HCP_ORG_ID,
                     (a.org_id if a.org_id is not None else
                      self.empty_uuid).bytes).addBuffer(
                          tags.base.HCP_INSTALLER_ID,
                          (a.ins_id if a.ins_id is not None else
                           self.empty_uuid).bytes).addInt32(
                               tags.base.HCP_ARCHITECTURE, a.architecture
                               if a.architecture is not None else 0).addInt32(
                                   tags.base.HCP_PLATFORM, a.platform if
                                   a.platform is not None else 0)).addSequence(
                                       tags.hbs.NOTIFICATION,
                                       task).addInt32(tags.hbs.NOTIFICATION_ID,
                                                      id))
        if None != expiry:
            toSign.addTimestamp(tags.base.EXPIRY, int(expiry))
        toSign = r.serialise(toSign)
        sig = s.sign(toSign)

        final = r.serialise(rSequence().addBuffer(
            tags.base.BINARY, toSign).addBuffer(tags.base.SIGNATURE, sig))

        return self._query('hbs.task_agent', {
            'task': final,
            'aid': str(a),
            'expiry': expiry
        })

    def hbs_addKey(self, oid, key):
        return self._query('hbs.add_key', {'oid': oid, 'key': key})
Exemplo n.º 4
0
         r'/hostobjects', 'HostObjects',
         r'/detects_data', 'JsonDetects',
         r'/detects', 'ViewDetects',
         r'/detect', 'ViewDetect',
         r'/hostchanges', 'HostChanges' )

web.config.debug = False
app = web.application( urls, globals() )

render = web.template.render( 'templates', base = 'base', globals = { 'json' : json,
                                                                      'tsToTime' : tsToTime,
                                                                      '_x_' : _x_,
                                                                      '_xm_' : _xm_,
                                                                      'hex' : hex,
                                                                      'sanitize' : sanitizeJson } )
eventRender = web.template.render( 'templates/custom_events', globals = { 'json' : json,
                                                                          'tsToTime' : tsToTime,
                                                                          '_x_' : _x_,
                                                                          '_xm_' : _xm_,
                                                                          'hex' : hex,
                                                                          'sanitize' : sanitizeJson } )

if len( sys.argv ) < 2:
    print( "Usage: python app.py beach_config [listen_port]" )
    sys.exit()

beach = Beach( sys.argv[ 1 ], realm = 'hcp' )
del( sys.argv[ 1 ] )
model = beach.getActorHandle( 'models', nRetries = 3, timeout = 30, ident = 'lc/0bf01f7e-62bd-4cc4-9fec-4c52e82eb903' )

app.run()
Exemplo n.º 5
0
                        dest='source')
    parser.add_argument(
        '-i',
        '--ident',
        type=str,
        required=False,
        default='endpointproxy/8e7a890b-8016-4396-b012-aec73d055dd6',
        help='Beach identity to use to request list of endpoints.',
        dest='ident')
    parser.add_argument(
        '-u',
        '--update',
        type=int,
        required=False,
        default=60,
        help='refresh list of available endpoints every X seconds.',
        dest='update')
    arguments = parser.parse_args()

    currentEndpoints = Set()
    beach = Beach(arguments.config, realm='hcp')
    endpointActors = beach.getActorHandle('c2/endpoint',
                                          nRetries=3,
                                          timeout=30,
                                          ident=arguments.ident)

    updateEndpoints(endpointActors, arguments.update)

    proxy = LcEndpointProxy(arguments.source, currentEndpoints)
    proxy.start()
    gevent.wait()
Exemplo n.º 6
0
class BEAdmin( object ):
    token = None
    
    def __init__( self, beach_config, token, timeout = 1000 * 10 ):
        self.token = token
        self.beach = Beach( beach_config, realm = 'hcp' )
        self.vHandle = self.beach.getActorHandle( 'c2/admin/1.0',
                                                  ident = 'cli/955f6e63-9119-4ba6-a969-84b38bfbcc05',
                                                  timeout = timeout,
                                                  nRetries = 3 )

    def _query( self, cmd, data = {} ):
        data[ 'token' ] = self.token
        response = self.vHandle.request( cmd, data )
        return response
    
    def testConnection( self ):
        return self._query( 'ping' )
    
    def hcp_getAgentStates( self, aid = None, hostname = None ):
        filters = {}
        if aid != None:
            filters[ 'agent_id' ] = aid
        if hostname != None:
            filters[ 'hostname' ] = hostname
        return self._query( 'hcp.get_agent_states', filters )
    
    def hcp_getPeriod( self ):
        return self._query( 'hcp.get_period' )
    
    def hcp_setPeriod( self, period ):
        return self._query( 'hcp.set_period', { 'period' : int( period ) } )
    
    def hcp_getEnrollmentRules( self ):
        return self._query( 'hcp.get_enrollment_rules' )
    
    def hcp_addEnrollmentRule( self, mask, externalIp, internalIp, newOrg, newSubnet, hostname ):
        return self._query( 'hcp.add_enrollment_rule', { 'mask' : mask,
                                                         'external_ip' : externalIp,
                                                         'internal_ip' : internalIp,
                                                         'new_org' : newOrg,
                                                         'new_subnet' : newSubnet,
                                                         'hostname' : hostname } )
    
    def hcp_delEnrollmentRule( self, mask, externalIp, internalIp, newOrg, newSubnet, hostname ):
        return self._query( 'hcp.del_enrollment_rule', { 'mask' : mask,
                                                         'external_ip' : externalIp,
                                                         'internal_ip' : internalIp,
                                                         'new_org' : newOrg,
                                                         'new_subnet' : newSubnet,
                                                         'hostname' : hostname } )
    
    def hcp_getTaskings( self ):
        return self._query( 'hcp.get_taskings' )
    
    def hcp_addTasking( self, mask, moduleId, hashStr ):
        return self._query( 'hcp.add_tasking', { 'mask' : mask, 'module_id' : int( moduleId ), 'hash' : hashStr } )
    
    def hcp_delTasking( self, mask, moduleId, hashStr ):
        return self._query( 'hcp.remove_tasking', { 'mask' : mask, 'module_id' : int( moduleId ), 'hash' : hashStr } )
    
    def hcp_getModules( self ):
        return self._query( 'hcp.get_modules' )
    
    def hcp_addModule( self, moduleId, binary, signature, description ):
        return self._query( 'hcp.add_module', { 'module_id' : moduleId, 'bin' : binary, 'signature' : signature, 'hash' : hashlib.sha256( binary ).hexdigest(), 'description' : description } )
    
    def hcp_delModule( self, moduleId, hashStr ):
        return self._query( 'hcp.remove_module', { 'module_id' : moduleId, 'hash' : hashStr } )
    
    def hcp_relocAgent( self, agentid, newOrg, newSubnet ):
        return self._query( 'hcp.reloc_agent', { 'agentid' : agentid,
                                                 'new_org' : newOrg,
                                                 'new_subnet' : newSubnet } )
    
    def hcp_getRelocations( self ):
        return self._query( 'hcp.get_relocations' )
    
    def hbs_getPeriod( self ):
        return self._query( 'hbs.get_period' )
    
    def hbs_setPeriod( self, period ):
        return self._query( 'hbs.set_period', { 'period' : int( period ) } )
    
    def hbs_getProfiles( self ):
        return self._query( 'hbs.get_profiles' )
    
    def hbs_addProfile( self, mask, config ):
        return self._query( 'hbs.set_profile', { 'mask' : mask, 'module_configs' : config } )
    
    def hbs_delProfile( self, mask ):
        return self._query( 'hbs.del_profile', { 'mask' : mask } )
    
    def hbs_taskAgent( self, toAgent, task, key, id, expiry = None, investigationId = None ):
        # Make sure it's a valid agentid
        a = AgentId( toAgent )
        if not a.isValid:
            return None
        if not type( task ) is rSequence:
            return None
        s = Signing( key )
        r = rpcm( isHumanReadable = True, isDebug = True )
        
        tags = Symbols()
        
        if investigationId is not None and '' != investigationId:
            task.addStringA( tags.hbs.INVESTIGATION_ID, investigationId )
        
        toSign = ( rSequence().addSequence( tags.base.HCP_ID, rSequence().addInt8( tags.base.HCP_ID_ORG, a.org )
                                                                         .addInt8( tags.base.HCP_ID_SUBNET, a.subnet )
                                                                         .addInt32( tags.base.HCP_ID_UNIQUE, a.unique )
                                                                         .addInt8( tags.base.HCP_ID_PLATFORM, a.platform )
                                                                         .addInt8( tags.base.HCP_ID_CONFIG, a.config ) )
                              .addSequence( tags.hbs.NOTIFICATION, task )
                              .addInt32( tags.hbs.NOTIFICATION_ID, id ) )
        if None != expiry:
            toSign.addTimestamp( tags.base.EXPIRY, int( expiry ) )
        toSign = r.serialise( toSign )
        sig = s.sign( toSign )
        
        final = r.serialise( rSequence().addBuffer( tags.base.BINARY, toSign )
                                        .addBuffer( tags.base.SIGNATURE, sig ) )
        
        return self._query( 'hbs.task_agent', { 'task' : final, 'agentid' : str( a ) } )
Exemplo n.º 7
0
            'public_ip':
            str(
                environment.get('X-FORWARDED-FOR',
                                environment.get('REMOTE_ADDR', '')))
        }

        resp = vHandle.request('beacon', data=clean_params)

        if resp.isSuccess:
            isSuccess = True
            response = '<html><h1>%s</h1></html>' % resp.data['resp']

    if isSuccess:
        status = '200 OK'

    start_response(status, [('Content-Type', 'text/html'),
                            ('Content-Length', str(len(response)))])

    return [str(response)]


beach = Beach(sys.argv[1], realm='hcp')
vHandle = beach.getActorHandle(
    'c2/beacon',
    nRetries=3,
    timeout=30,
    ident='http/5bc10821-2d3f-413a-81ee-30759b9f863b')

server = wsgi.WSGIServer(('', 80), handle_beacon, spawn=100)

server.serve_forever()
Exemplo n.º 8
0
        printFailure(
            "LC Web UI doesn't seem to be running, you can ignore this error if it is running from a different appliance.",
            isFatal=False)

    if 0 == os.system(
            'ps -elf | grep -E ".*beach\\.dashboard.*" | grep -v grep > /dev/null'
    ):
        printSuccess('Beach dashboard is running.')
    else:
        printFailure(
            "Beach dashboard doesn't seem to be running, you can ignore this error if it is running from a different appliance.",
            isFatal=False)

    printStep('CORE ACTORS')

    allActors = BEACH.getActorHandle('', timeout=60)
    futures = allActors.requestFromAll('z', data={})
    isSuccess = True
    nActors = 0
    while not futures.isFinished():
        if not futures.waitForResults(timeout=30):
            isSuccess = False
            break
        results = futures.getNewResults()
        for resp in results:
            handleActorResponse(resp)
            if not resp.isSuccess:
                isSuccess = False
                break
            nActors += 1
    allActors.close()
Exemplo n.º 9
0
print( "Creating ping actor in resource beach node." )
a1 = beach.addActor( 'Ping', 'pingers', strategy = 'resource' )
print( json.dumps( a1, indent = 4 ) )

print( "Creating pong actor in affinity( pingers ) beach node." )
a2 = beach.addActor( 'Pong', 'pongers', strategy = 'affinity', strategy_hint = 'pingers' )
print( json.dumps( a2, indent = 4 ) )

print( "Creating pong actor in isolation." )
a3 = beach.addActor( 'Pong', 'pongers', isIsolated = True )
print( json.dumps( a3, indent = 4 ) )

print( "Idling for a few seconds..." )
time.sleep( 15 )

print( "Querying for beach directory." )
d = beach.getDirectory()
print( json.dumps( d, indent = 4 ) )

print( "Trying some queries to the cluster." )
vHandle = beach.getActorHandle( 'pongers' )
print( "Issuing ping" )
resp = vHandle.request( 'ping', data = { 'source' : 'outside' }, timeout = 10 )
print( "Received: %s" % str( resp ) )

time.sleep( 2 )
print( "Flushing beach." )
f = beach.flush()
print( json.dumps( f, indent = 4 ) )

beach.close()
Exemplo n.º 10
0
        params = urlparse.parse_qs("".join(params).lstrip("&"), strict_parsing=True)
    except:
        params = {}

    if "pl" in params:
        clean_params = {
            "payload": params["pl"][0],
            "public_ip": str(environment.get("X-FORWARDED-FOR", environment.get("REMOTE_ADDR", ""))),
        }

        resp = vHandle.request("beacon", data=clean_params)

        if resp.isSuccess:
            isSuccess = True
            response = "<html><h1>%s</h1></html>" % resp.data["resp"]

    if isSuccess:
        status = "200 OK"

    start_response(status, [("Content-Type", "text/html"), ("Content-Length", str(len(response)))])

    return [str(response)]


beach = Beach(sys.argv[1], realm="hcp")
vHandle = beach.getActorHandle("c2/beacon", nRetries=3, timeout=30, ident="http/5bc10821-2d3f-413a-81ee-30759b9f863b")

server = wsgi.WSGIServer(("", 80), handle_beacon, spawn=100)

server.serve_forever()
Exemplo n.º 11
0
                                      'msTsToTime': msTsToTime,
                                      '_x_': _x_,
                                      '_xm_': _xm_,
                                      'hex': hex,
                                      'sanitize': sanitizeJson,
                                      'EventInterpreter': EventInterpreter,
                                      'sorted': sorted
                                  })

if len(sys.argv) < 2:
    print("Usage: python app.py beach_config [listen_port]")
    sys.exit()

beach = Beach(sys.argv[1], realm='hcp')
del (sys.argv[1])
model = beach.getActorHandle('models',
                             nRetries=3,
                             timeout=30,
                             ident='lc/0bf01f7e-62bd-4cc4-9fec-4c52e82eb903')
capabilities = beach.getActorHandle(
    'analytics/capabilitymanager',
    nRetries=3,
    timeout=60,
    ident='lc/0bf01f7e-62bd-4cc4-9fec-4c52e82eb903')
sensordir = beach.getActorHandle(
    'c2/sensordir',
    nRetries=3,
    timeout=30,
    ident='lc/0bf01f7e-62bd-4cc4-9fec-4c52e82eb903')

app.run()
Exemplo n.º 12
0
                conf = userConf['config']
    else:
        conf = args.config

    if conf is None:
        parser.error('no config specified and ~/.beach is not a valid config.')
    else:
        if args.req_realm is None and args.req_cat is None and args.req_cmd is None and args.req_ident is None:
            app = BeachShell(conf)
            app.cmdloop()
        elif args.req_realm is None or args.req_cat is None or args.req_cmd is None:
            parser.error('--req-* components missing to execute a request.')
        else:
            beach = Beach(conf, realm=args.req_realm)
            h = beach.getActorHandle(args.req_cat,
                                     ident=args.req_ident,
                                     timeout=args.req_timeout)

            if 0 == h.getNumAvailable():
                h.close()
                beach.close()
                eprint("no actors available in category")
                sys.exit(1)

            if args.is_broadcast:
                futures = h.requestFromAll(args.req_cmd, data=args.req_data)
            else:
                resp = h.request(args.req_cmd, data=args.req_data)
                h.close()
                beach.close()
Exemplo n.º 13
0
print("Creating pong actor in affinity( pingers ) beach node.")
a2 = beach.addActor('Pong',
                    'pongers',
                    strategy='affinity',
                    strategy_hint='pingers')
print(json.dumps(a2, indent=4))

print("Creating pong actor in isolation.")
a3 = beach.addActor('Pong', 'pongers', isIsolated=True)
print(json.dumps(a3, indent=4))

print("Idling for a few seconds...")
time.sleep(15)

print("Querying for beach directory.")
d = beach.getDirectory()
print(json.dumps(d, indent=4))

print("Trying some queries to the cluster.")
vHandle = beach.getActorHandle('pongers')
print("Issuing ping")
resp = vHandle.request('ping', data={'source': 'outside'}, timeout=10)
print("Received: %s" % str(resp))

time.sleep(2)
print("Flushing beach.")
f = beach.flush()
print(json.dumps(f, indent=4))

beach.close()
Exemplo n.º 14
0
renderFullPage = web.template.render( 'templates', base = 'base_full', globals = { 'json' : json,
                                                                                   'msTsToTime' : msTsToTime,
                                                                                   '_x_' : _x_,
                                                                                   '_xm_' : _xm_,
                                                                                   'hex' : hex,
                                                                                   'sanitize' : sanitizeJson,
                                                                                   'EventInterpreter' : EventInterpreter,
                                                                                   'md' : doMarkdown,
                                                                                   'sorted' : sorted,
                                                                                   'InvestigationNature' : InvestigationNature,
                                                                                   'InvestigationConclusion' : InvestigationConclusion } )
eventRender = web.template.render( 'templates/custom_events', globals = { 'json' : json,
                                                                          'msTsToTime' : msTsToTime,
                                                                          '_x_' : _x_,
                                                                          '_xm_' : _xm_,
                                                                          'hex' : hex,
                                                                          'sanitize' : sanitizeJson,
                                                                          'EventInterpreter' : EventInterpreter,
                                                                          'sorted' : sorted } )

if len( sys.argv ) < 2:
    print( "Usage: python app.py beach_config [listen_port]" )
    sys.exit()

beach = Beach( sys.argv[ 1 ], realm = 'hcp' )
del( sys.argv[ 1 ] )
model = beach.getActorHandle( 'models', nRetries = 3, timeout = 30, ident = 'lc/0bf01f7e-62bd-4cc4-9fec-4c52e82eb903' )
capabilities = beach.getActorHandle( 'analytics/capabilitymanager', nRetries = 3, timeout = 60, ident = 'lc/0bf01f7e-62bd-4cc4-9fec-4c52e82eb903' )
sensordir = beach.getActorHandle( 'c2/sensordir', nRetries = 3, timeout = 30, ident = 'lc/0bf01f7e-62bd-4cc4-9fec-4c52e82eb903' )

app.run()
Exemplo n.º 15
0
        if not info.isSuccess:
            raiseUnavailable(str(info))

        return info.data


###############################################################################
# BOILER PLATE
###############################################################################
os.chdir(os.path.dirname(os.path.abspath(__file__)))

urls = (r'/', 'Index', r'/sensorstate', 'SensorState', r'/timeline',
        'Timeline', r'/lastevents', 'LastEvents', r'/detects', 'Detects',
        r'/hostchanges', 'HostChanges', r'/objectloc', 'ObjectLocation')

web.config.debug = False
app = web.application(urls, globals())

if len(sys.argv) < 2:
    print("Usage: python app.py beach_config [listen_port]")
    sys.exit()

beach = Beach(sys.argv[1], realm='hcp')
del (sys.argv[1])
model = beach.getActorHandle('models',
                             nRetries=3,
                             timeout=30,
                             ident='rest/be41bb0f-449a-45e9-87d8-ef4533336a2d')

app.run()