本文整理汇总了Python中crits.services.service.CRITsService类的典型用法代码示例。如果您正苦于以下问题:Python CRITsService类的具体用法?Python CRITsService怎么用?Python CRITsService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CRITsService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reset_all
def reset_all(self):
"""
Recreate the services collection.
"""
logger.debug("Dropping service collection")
CRITsService.drop_collection()
self._instantiate_collection()
self._update_status_all()
示例2: enabled_services
def enabled_services(status=True):
"""
Return names of services which are enabled.
"""
if status:
services = CRITsService.objects(enabled=True,
status="available")
else:
services = CRITsService.objects(enabled=True)
return [s.name for s in services]
示例3: triage_services
def triage_services(status=True):
"""
Return names of services set to run on triage.
"""
if status:
services = CRITsService.objects(run_on_triage=True,
status="available")
else:
services = CRITsService.objects(run_on_triage=True)
return [s.name for s in services]
示例4: export_config
def export_config(request, name):
"""
Export a service's configuration.
"""
# TODO: Present a form to the admin to select file format
# Format is either ini or json
s = CRITsService.objects(name=name).first()
if s:
try:
data = json.dumps(s.config.to_dict())
except (ValueError, TypeError) as e:
error = 'Failed to export %s configuration, please check ' \
'error logs.' % name
logger.error(error)
logger.error(e)
return render_to_response('error.html', {'error': error},
RequestContext(request))
response = HttpResponse(data, content_type='text/plain')
response['Content-Length'] = len(data)
fn = name + '.conf'
response['Content-Disposition'] = 'attachment; filename="%s"' % fn
return response
else:
error = 'Service "%s" does not exist!' % name
render_to_response('error.html', {'error': error},
RequestContext(request))
示例5: detail
def detail(request, name):
"""
List all details about a single service.
"""
service = CRITsService.objects(name=name,
status__ne="unavailable").first()
if not service:
error = 'Service "%s" is unavailable. Please review error logs.' % name
return render_to_response('error.html', {'error': error},
RequestContext(request))
# TODO: fix code so we don't have to do this
service = service.to_dict()
service_class = crits.service_env.manager.get_service_class(name)
if user_is_admin(request.user):
clean = False
# Only show errors if the user is an admin.
error = _get_config_error(service)
else:
# Clean all non-public values for a non-admin
clean = True
error = None
# Replace the dictionary with a list (to preserve order the options
# were defined in the Service class), and remove data from any which
# are not editable)
service['config_list'] = service_class.format_config(service['config'],
clean=clean)
del service['config']
return render_to_response('services_detail.html',
{'service': service, 'config_error': error},
RequestContext(request))
示例6: update_status
def update_status(self, service_name):
"""
Look up a service, and verify it is configured correctly
"""
service = CRITsService.objects(name=service_name).first()
self._update_status(service)
示例7: enabled_services
def enabled_services(self):
"""
Return names of services which are both available and enabled.
"""
services = CRITsService.objects(enabled=True)
return [s.name for s in services if s.name in self._services]
示例8: _instantiate_collection
def _instantiate_collection(self):
"""
Save services information in a Mongo collection.
"""
logger.debug("Storing service metadata")
for service_class in self._services.values():
#If not already in collection
current = CRITsService.objects(name=service_class.name).first()
if not current:
# Add the new service
self._add_to_collection(service_class)
else:
logger.debug("Service %s already exists, checking version." \
% service_class.name)
# Check the current version
logger.debug('New version: %s -- Old version: %s' \
% (service_class.version, current.version))
if (StrictVersion(service_class.version) !=
StrictVersion(current['version'])):
self._update_service(service_class)
示例9: get_form
def get_form(request, name, crits_type, identifier):
"""
Get a configuration form for a service.
"""
response = {}
response['name'] = name
analyst = request.user.username
service = CRITsService.objects(name=name, status__ne="unavailable").first()
if not service:
msg = 'Service "%s" is unavailable. Please review error logs.' % name
response['error'] = msg
return HttpResponse(json.dumps(response), content_type="application/json")
# Get the class that implements this service.
service_class = crits.services.manager.get_service_class(name)
config = service.config.to_dict()
form_html = service_class.generate_runtime_form(analyst,
config,
crits_type,
identifier)
if not form_html:
return service_run(request, name, crits_type, identifier)
else:
response['form'] = form_html
return HttpResponse(json.dumps(response), content_type="application/json")
示例10: list
def list(request):
"""
List all services.
"""
all_services = CRITsService.objects().order_by('+name')
return render_to_response('services_list.html', {'services': all_services},
RequestContext(request))
示例11: triage_services
def triage_services(self):
"""
Return names of available services set to run on triage.
"""
# TODO: This doesn't care if the service is enabled, should it?
# What is the correct behavior when enabled=False, run_on_triage=True?
services = CRITsService.objects(run_on_triage=True)
return [s.name for s in services if s.name in self._services]
示例12: get_supported_services
def get_supported_services(crits_type):
"""
Get the supported services for a type.
"""
services = CRITsService.objects(enabled=True)
for s in services:
if s.supported_types == 'all' or crits_type in s.supported_types:
yield s.name
示例13: get_supported_services
def get_supported_services(crits_type):
"""
Get the supported services for a type.
"""
services = CRITsService.objects(enabled=True)
for s in sorted(services, key=lambda s: s.name.lower()):
if s.supported_types == 'all' or crits_type in s.supported_types:
yield s.name
示例14: get_config
def get_config(service_name):
"""
Get the configuration for a service.
"""
service = CRITsService.objects(name=service_name).first()
if not service:
return None
return service.config
示例15: get_config
def get_config(self, service_name):
"""
Get the configuration for a service.
"""
service = CRITsService.objects(name=service_name).first()
try:
return service.config
except Exception, e:
logger.exception(e)
return self.get_service_class(service_name).build_default_config()