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.
ServiceHolder
(team, subtype, override=None)¶ This is the base unit that gets passed around the service scanner. It handles automatically merging the configuration for overrides and provides easy access to custom configuration.
Variables: - team – The team the information is being held for
- subtype – The service sub type for this check
- override – The service override for this team, if any
-
refresh_from_db
()¶ Refresh any changes from the database.
-
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
-
is_authenticated
(service_name)¶ Checks if a given service short name requires authenication :param service_name: short name of a service :return: True if the
Raises: ValueError if the given short name is not found in the service registry
-
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 theshort_name
.Parameters: service_type (ServiceType) – Raises: KeyError – When a duplicate short_name
is encountered.
-
resolve_check
(service_holder)¶ Get the appropriate service type for a given check.
Parameters: service_holder (ServiceHolder) – Return type: ServiceType
-
validate_service
(service)¶ Performs some validation for the service form frontend. TODO: Update this to use whatever the frontend needs
Parameters: service (base.forms.ServiceForm) – The not-yet saved form Raises: ValidationError –
-
-
class
iscore.servicecheck.registry.
ServiceType
¶ 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
-
configuration_help
= ''¶ Provide a description of what fields are needed in the service data
-
classmethod
do_check
(service)¶ Is run by the service worker to actually perform the check.
Parameters: service (base.models.Service) – Returns: The results of the scan (service, score, error)
-
classmethod
do_mass_check
(services)¶ Is run by the service worker to perform a check against all teams at once.
Parameters: services) (list(base.models.Service) – Returns: The results of the scan [(service, score, error)]
-
classmethod
end_check
(service)¶ Is run by the team worker after the check is done :param base.models.Service service:
-
classmethod
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
-
classmethod
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
-
classmethod
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. Remote Admin).
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.
-
classmethod
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
-
static
validate_config
()¶ Validates the configuration for the service type.
-
iscore.servicecheck.
register
(cls)¶ A decorator to simplify registering a service Type with the registry.
Parameters: cls – The ServiceType class Returns: The registered ServiceType