Custom Service Check Reference

exception iscore.servicecheck.registry.InvalidConfigurationError(service=None, *args, **kwargs)

Indicates that a service check was incorrectly configured. If this exception is raised the check MUST NOT report a score to the results queue. The ServiceWorker will automatically report a zero score with the text of this exception as the error message.

class iscore.servicecheck.registry.MassServiceWorker(services, logger, checks)

Reponsible for setting up and running mass checks.

This worker IS allowed to talk to the database.

Variables:logger (logging.Logger) –
class iscore.servicecheck.registry.ServiceRegistry

The registry that contains all the service types.

The registry is responsible for keeping track of all registered service types as well as running the actual service scan. The registry can be queried to get registered service types by the frontend in order to help with validation and field population.

get_choices()

Generate a tuple suitable for a form fields choices attribute.

Return tuple:The choices tuple based on registered service types
process_results(service_logger)

Process the service scanner results and insert them into the database.

Parameters:service_logger (logging.Logger) –
register(service_type)

Register a service type.

Expects a class that extends ServiceType.

Registered types must have a unique short_name. It is therefore recommended that custom checks use a prefix for the short_name.

Parameters:service_type (ServiceType) –
Raises:KeyError – When a duplicate short_name is encountered.
validate_service(service)

Performs some validation for the service form frontend.

Parameters:service (base.forms.ServiceForm) – The not-yet saved form
Raises:ValidationError
class iscore.servicecheck.registry.ServiceType(results, scan_logger)

Defines a type of service check that the service scanner knows how to perform. All services MUST be a subclass of this type. The ServiceRegistry keeps track of all registered service types.

Variables:
  • results – A reference to the results queue
  • logger – The logger being used by the current scan
authenticated = False

If true, this service is marked as expecting credentials. If None, credentials are optional

do_check(service)

Run by the service worker to actually perform the check.

Parameters:service (base.models.Service) –
do_mass_check(services)

Run by the service worker to perform a check against all teams at once.

Parameters:services) (list(base.models.Service) –
end_check(service)

Run by the team worker after the check is done :param base.models.Service service:

get_credentials(service)

Gets the credentials to use for a service check. Defaults to the ones specified by service

Parameters:service (base.models.Service) – The service we are checking
Return tuple:Username and Password
log(service, action, success=False)

Log the failure or success message in a standardized format.

<thread name>: <Success|FAIL>: Team <number> <service_name> <action> to <url>

The format allows for easier parsing of the scan logs.

Parameters:
  • service (base.models.Service) – The service being logged
  • action (str) – Text action so the log message makes sense
  • success (bool) – Whether the check was a success or not
mass_check = False

Whether this service type checks all teams at once

multi_protocol = False

If true, this service type is a composite of other service types based on a specified criteria.

name = None

The friendly name of the service type

post_check(service)

Run by the service worker to perform any cleanup actions that need to be done.

Parameters:service (base.models.Service) –
pre_check(service)

Run by the service worker before a check is performed.

Parameters:service (base.models.Service) –
report_score(service, score, error)

Helper method to ensure the score is reported to the results queue in the correct structure.

Parameters:
resolve_credentials(services)

Resolves any Team Specific Info or Team Info Pools and sets service.username and service.password as appropriate.

Team/Mass Check Worker Only

Parameters:services (base.models.Service) – Either a single service or list of services
resolve_multi(service)

Returns the name of the service type that should handle the service.

Usually based on port. Useful for services that have some leeway in what protocol can be implemented (i.e. Databases).

Return ‘self’ if this object should handle the service.

Parameters:service (base.models.Service) – The service to check against
Return str:The short name of the type that should handle the given service
short_name = None

The short name of the service type.

start_check(service)

Run by the team worker before it spawns the service worker.

Parameters:service (base.models.Service) –
sub_protocols = None

List of protocols that resolve_multi could return if multi_protocol is True

class iscore.servicecheck.registry.ServiceWorker(service, logger, check)

Responsible for running one service check against one team.

This working IS NOT allowed to touch the database.

Variables:
class iscore.servicecheck.registry.TeamWorker(services, team, logger)

Responsible for setting up the service checks for a team and spawning Service Workers for each service check for the team.

This worker IS allowed to touch the database.

iscore.servicecheck.register(cls)

A decorator to simplify registering a service Type with the registry.

Parameters:cls – The ServiceType class
Returns:The registered ServiceType