How to use the cbapi.CbApi function in cbapi

To help you get started, we’ve selected a few cbapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github carbonblack / cbapi / client_apis / python / example / group_add.py View on Github external
def main(argv):
    parser = build_cli_parser()
    opts, args = parser.parse_args(argv)
    if not opts.server_url or not opts.token or not opts.name or not opts.sensorbackend_server:
        print "Missing required param; run with --help for usage"
        print "Must include the first two fields with server info as well as Sensor Group Name and Server URL"
        sys.exit(-1)

    # build a cbapi object
    #    
    cb = cbapi.CbApi(opts.server_url, token=opts.token, ssl_verify=opts.ssl_verify)


    teams = cb.team_enum()

    
    #Deals with the case that team_access was not in the input 
    #
    if opts.team_access is None:
        ## Default is all have no access
        access_command = "n"*len(teams)
    else:
        #Verifies that the correct number of inputs for opts.team_access was written down.
        #
        access_command = opts.team_access
        if len(teams) != len(access_command):
            print "%s is not a valid input." %(access_command)
github carbonblack / cbapi / client_apis / python / example / team_info.py View on Github external
def main(argv):
    parser = build_cli_parser()
    opts, args = parser.parse_args(argv)
    if not opts.server_url or not opts.token or (not opts.teamname and not opts.teamid):
        print "Missing required param; run with --help for usage"
        print "One of -t or -i must be specified"
        sys.exit(-1)

    # build a cbapi object
    #
    cb = cbapi.CbApi(opts.server_url, token=opts.token, ssl_verify=opts.ssl_verify)

    if not opts.teamid:
        team = cb.team_get_team_by_name(opts.teamname)
        if team is None:
            print "-> No configured team with name '%s' found!" % (opts.teamname) 
            sys.exit(-1)
        else:
            id = team['id']
    else:
        id = opts.teamid
        does_exist = False
        for team in cb.team_enum():
            if id == team['id']:
                does_exist = True

        if not does_exist:
github carbonblack / cbapi / client_apis / python / example / sensor_info.py View on Github external
def main(argv):
    parser = build_cli_parser()
    opts, args = parser.parse_args(argv)
    if not opts.url or not opts.token or not opts.sensorid:
        print "Missing required param; run with --help for usage"
        sys.exit(-1)

    # build a cbapi object
    #
    cb = cbapi.CbApi(opts.url, token=opts.token, ssl_verify=opts.ssl_verify)

    # enumerate sensors 
    #
    sensor = cb.sensor(opts.sensorid)

    # output
    #
    for key in sensor.keys():
        print "%-35s : %s" % (key, sensor[key])
github carbonblack / cbapi / client_apis / python / example / team_del.py View on Github external
def main(argv):
    parser = build_cli_parser()
    opts, args = parser.parse_args(argv)

    if not opts.server_url or not opts.token or (not opts.teamname and not opts.teamid):
        print "Missing required param; run with --help for usage"
        print "One of -t or -i must be specified"
        sys.exit(-1)
    
    
    # build a cbapi object
    cb = cbapi.CbApi(opts.server_url, token=opts.token, ssl_verify=opts.ssl_verify)

    if not opts.teamid:
        # Find the team id, if no teamid is given
        #
        team = cb.team_get_team_by_name(opts.teamname)
        id = team['id']
        if id is None:
            print "-> No team found with team name: %s" % (opts.teamname)
            sys.exit(-1)
    else:        
        id = opts.teamid
        team = cb.team_get_team_by_id(id) 
        
        if not team:
            print "->No team found with team id: %s" %(id) 
            sys.exit(-1)
github carbonblack / cbapi / client_apis / python / example / user_info.py View on Github external
def main(argv):
 
    parser = build_cli_parser()
    opts, args = parser.parse_args(argv)
    if not opts.server_url or not opts.token or (not opts.username and (not opts.first_name or not opts.last_name)) :
        print "Missing required param; run with --help for usage"
        print "Either username must be satisfied -u or first and last name must be satisfied -f and -l"
        sys.exit(-1)

    # build a cbapi object
    #
    cb = cbapi.CbApi(opts.server_url, token=opts.token, ssl_verify=opts.ssl_verify)

  #  import pdb; pdb.set_trace()
	
    if not opts.username:
        user = cb.user_get_user_by_name(opts.first_name, opts.last_name)
        if user is None:
            print "-> No configured user with name '%s %s' found!" % (opts.first_name, opts.last_name) 
            sys.exit(-1)
        else:
             username = user['username']
    else:
        username = opts.username
        #Check if the username exists
        does_exist = False

        for user in cb.user_enum():
github carbonblack / cbapi / client_apis / python / example / feed_del.py View on Github external
def main(argv):
    parser = build_cli_parser()
    opts, args = parser.parse_args(argv)
    if not opts.server_url or not opts.token or (not opts.feedname and not opts.feedid):
      print "Missing required param; run with --help for usage"
      print "One of -f or -i must be specified"
      sys.exit(-1)

    # build a cbapi object
    #
    cb = cbapi.CbApi(opts.server_url, token=opts.token, ssl_verify=opts.ssl_verify)

    if not opts.feedid:
      id = cb.feed_get_id_by_name(opts.feedname)
      if id is None:
        print "-> No configured feed with name '%s' found!" % (opts.feedname) 
        return
    else:
      id = opts.feedid

    # delete the feed
    #
    cb.feed_del(id)

    print "-> Feed deleted [id=%s]" % (id,)
github carbonblack / cbapi / client_apis / python / example / feed_add.py View on Github external
def main(argv):
    parser = build_cli_parser()
    opts, args = parser.parse_args(argv)
    if not opts.server_url or not opts.token or not opts.feed_url:
        print "Missing required param; run with --help for usage"
        sys.exit(-1)

    # build a cbapi object
    #
    cb = cbapi.CbApi(opts.server_url, token=opts.token, ssl_verify=opts.ssl_verify)

    # add the feed.  The feed metadata (name, icon, etc.) will be pulled from
    # the feed itself  
    #
    results = cb.feed_add_from_url(opts.feed_url, opts.enabled, opts.validate_server_cert, opts.use_proxy)

    print
    print "-> Feed added [id=%s]" % (results['id'])
    print "   -------------------------"
    print "   Name     : %s" % (results['name'],)
    print "   Display  : %s" % (results['display_name'],)
    print
github carbonblack / cbapi / client_apis / python / example / feed_action_update.py View on Github external
def main(argv):
    parser = build_cli_parser()
    opts, args = parser.parse_args(argv)
    if not opts.server_url or not opts.token or not opts.id or not opts.action_id or not opts.action_type_id:
      print "Missing required param; run with --help for usage"
      sys.exit(-1)

    # build a cbapi object
    #

    cb = cbapi.CbApi(opts.server_url, token=opts.token, ssl_verify=opts.ssl_verify)

    #Check to make sure the user supplies a correct action_type_id
    #

    type = opts.action_type_id
    if not (int(type) == int(0) or int(type) == int(1) or int(type) == int(3)):
        print "action_type_id must be either 0,1,or 3"
        sys.exit(-1)

    #Check to make sure the action isn't already enabled
    #
    
    curr_actions = cb.feed_action_enum(opts.id)
    for action in curr_actions:
        if int(action['action_type']) == int(opts.action_type_id):
            print "action already enabled"
github carbonblack / cbapi / client_apis / python / example / network_subnet_search.py View on Github external
def __init__(self, url, token, ssl_verify):
        self.cb = CbApi(url, token=token, ssl_verify=ssl_verify)
        self.cb_url = url

        # set up some stat tracking
        self.stats = {}
        self.stats['total_processes'] = 0
        self.stats['total_netconns'] = 0
        self.stats['matching_netconns'] = 0
        self.stats['output_errors'] = 0
        self.stats['process_errors'] = 0
github carbonblack / cb-reporting / redis_cbapi_wrapper.py View on Github external
def _cb(self):
        if not self._cbapi:
            self._cbapi = cbapi.CbApi(self._cburl, token=self._token, ssl_verify=False)

        #traceback.print_stack()
        # Take this out if you want ... just helps me realize when I am going remote for the data versus local in redis.
        #print "Using remote!"
        return self._cbapi