예제 #1
0
class Suppression(resource.Resource):
    base_path = 'suppressions'
    resources_key = 'values'
    service = monitoring_service.MonitoringService()

    # capabilities
    allow_create = True
    allow_delete = True
    allow_list = True
    allow_retrieve = True
    allow_update = True

    # Properties
    #: A list of alarm IDs for determining notification suppression
    #: *Type: list*
    alarms = resource.prop('alarms', type=list)
    #: A list of check IDs for determining notification suppression
    #: *Type: list*
    checks = resource.prop('checks', type=list)
    #: The Unix timestamp in milliseconds that the suppression will end.
    #: Specify `0` to use the current time. *Type: int*
    ends_at = resource.prop('end_time', type=int)
    #: A list of entity IDs for determining notification suppression
    #: *Type: list*
    entities = resource.prop('entities', type=list)
    #: A friendly label for the suppression
    name = resource.prop('label')
    #: A list of notification plans IDs for determining notification plans
    #: *Type: list*
    notification_plans = resource.prop('notification_plans', type=list)
    #: The Unix timestamp in milliseconds that the suppression will start.
    #: Specify `0` to use the current time. *Type: int*
    starts_at = resource.prop('start_time', type=int)
class Notification(resource.Resource):
    base_path = 'notifications'
    resources_key = 'values'
    service = monitoring_service.MonitoringService()

    # capabilities
    allow_create = True
    allow_delete = True
    allow_list = True
    allow_retrieve = True
    allow_update = True

    # Properties
    #: Details specific to the notification. *Type: dict*
    details = resource.prop('details', type=dict)
    #: A friendly label for the notification type
    name = resource.prop('label')
    #: The type of notification to send
    type = resource.prop('type')

    def test(self, session):
        """Test an existing notification

        The notification comes from the same server that the alert messages
        come from. One use for this test is to verify that your firewall is
        configured properly.

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :returns: ``dict``
        """
        url = utils.urljoin(self.base_path, self.id, 'test')
        return session.post(url, endpoint_filter=self.service).body
class MonitoringZone(resource.Resource):
    base_path = 'monitoring_zones'
    resources_key = 'values'
    service = monitoring_service.MonitoringService()

    # capabilities
    allow_list = True
    allow_retrieve = True

    # Properties
    #: Country Code
    country = resource.prop('country_code')
    #: A friendly label for the monitoring zone
    name = resource.prop('label')
    #: Source IP list for the monitoring zone. *Type: list*
    source_ip_addresses = resource.prop('source_ips', type=list)

    def traceroute(self, session, target, target_resolver="IPv4"):
        """Issue a traceroute from a monitoring zone to a host

        :param str target: Hostname or IP address
        :param str target_resolver: `IPv4` or `IPv6`
        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :returns: ``list``
        """
        body = {"target": target, "target_resolver": target_resolver}
        url = utils.urljoin(self.base_path, self.id, 'traceroute')
        resp = session.post(url, endpoint_filter=self.service, json=body).body
        return resp['result']
class SuppressionLog(resource.Resource):
    base_path = 'suppression_logs'
    resources_key = 'values'
    service = monitoring_service.MonitoringService()

    # capabilities
    allow_list = True

    # Properties
    #: The ID of the alarm
    alarm_id = resource.prop('alarm_id')
    #: The ID of the check
    check_id = resource.prop('check_id')
    #: The ID of the entity
    entity_id = resource.prop('entity_id')
    #: The ID of the notification plan
    notification_plan_id = resource.prop('notification_plan_id')
    #: Status
    status = resource.prop('state')
    #: List of suppression IDs. *Type: list*
    suppressions = resource.prop('suppressions', type=list)
    #: Timestamp. *Type: int*
    timestamp = resource.prop('timestamp', type=int)
    #: The ID of the transaction
    transaction = resource.prop('transaction_id')
class NotificationPlan(resource.Resource):
    base_path = 'notification_plans'
    resources_key = 'values'
    service = monitoring_service.MonitoringService()

    # capabilities
    allow_create = True
    allow_delete = True
    allow_list = True
    allow_retrieve = True
    allow_update = True

    # Properties
    #: A friendly label for the notification plan
    name = resource.prop('label')
    #: Arbitrary key/value pairs. *Type: dict*
    metadata = resource.prop('metadata', type=dict)
    #: The list of recipients to notify when the state is `CRITICAL`.
    #: *Type: list*
    recipients_on_critical = resource.prop('critical_state', type=list)
    #: The list of recipients to notify when the state is `OK`.
    #: *Type: list*
    recipients_on_ok = resource.prop('ok_state', type=list)
    #: The list of recipients to notify when the state is `WARNING`.
    #: *Type: list*
    recipients_on_warning = resource.prop('warning_state', type=list)
 def test_service(self):
     sot = monitoring_service.MonitoringService()
     self.assertEqual("rax:monitor", sot.service_type)
     self.assertEqual("public", sot.interface)
     self.assertIsNone(sot.region)
     self.assertEqual("cloudMonitoring", sot.service_name)
     self.assertEqual(1, len(sot.valid_versions))
     self.assertEqual("v1", sot.valid_versions[0].module)
     self.assertEqual("v1.0", sot.valid_versions[0].path)
class NotificationType(resource.Resource):
    base_path = 'notification_types'
    resources_key = 'values'
    service = monitoring_service.MonitoringService()

    # capabilities
    allow_list = True
    allow_retrieve = True

    # Properties
    #: Details specific to the notification type. *Type: list*
    details = resource.prop('fields', type=list)
예제 #8
0
class Alarm(resource.Resource):
    base_path = '/entities/%(entity_id)s/alarms'
    resources_key = 'values'
    service = monitoring_service.MonitoringService()

    # capabilities
    allow_create = True
    allow_delete = True
    allow_list = True
    allow_retrieve = True
    allow_update = True

    # Properties
    #: List of active suppressions. *Type: list*
    active_suppressions = resource.prop('active_suppressions', type=list)
    #: The ID of the check to alert on
    check_id = resource.prop('check_id')
    #: Creation timestamp.
    #: Time is shown in Coordinated Universal Time (UTC) as the number
    #: of milliseconds that have elapsed since January 1, 1970. *Type: int*
    created_at = resource.prop('created_at', type=int)
    #: The alarm DSL for describing alerting conditions and their output states
    criteria = resource.prop('criteria')
    # The ID of the entity
    entity_id = resource.prop('entity_id')
    #: Disables the alarm. *Type: bool*
    is_disabled = resource.prop('disabled', type=format.BoolStr)
    #: Arbitrary key/value pairs. *Type: dict*
    metadata = resource.prop('metadata', type=dict)
    #: A friendly label for an alarm
    name = resource.prop('label')
    #: The id of the notification plan to execute when the state changes
    notification_plan_id = resource.prop('notification_plan_id')
    #: List of scheduled suppressions. *Type: list*
    scheduled_suppressions = resource.prop('scheduled_suppressions', type=list)
    #: Update timestamp.
    #: Time is shown in Coordinated Universal Time (UTC) as the number
    #: of milliseconds that have elapsed since January 1, 1970. *Type: int*
    updated_at = resource.prop('updated_at', type=int)

    def notification_history(self, session):
        """Lists alarm notification history for the alarm and check

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :returns: ``list``
        """
        url = utils.urljoin('entities', self.entity_id, 'alarms', self.id,
                            'notification_history', self.check_id)
        resp = session.get(url, endpoint_filter=self.service).json()
        return resp['values']
class Overview(resource.Resource):
    base_path = '/views/overview'
    resources_key = 'values'
    service = monitoring_service.MonitoringService()

    # capabilities
    allow_list = True

    # Properties
    #: List of alarms. *Type: list*
    alarms = resource.prop('alarms', type=list)
    #: List of checks. *Type: list*
    checks = resource.prop('checks', type=list)
    # The ID of the entity. *Type: Entity*
    entity = resource.prop('entity_id', type=dict)
    #: List of alarm states. *Type: list*
    latest_alarm_states = resource.prop('latest_alarm_states', type=list)
예제 #10
0
class AgentToken(resource.Resource):
    base_path = 'agent_tokens'
    resources_key = 'values'
    service = monitoring_service.MonitoringService()

    # capabilities
    allow_create = True
    allow_delete = True
    allow_list = True
    allow_retrieve = True
    allow_update = True

    # Properties
    #: Optional description string
    name = resource.prop('label')
    #: The agent token ID. Agent tokens are used to authenticate monitoring
    #: agents to the monitoring service. Multiple agents on an account can
    #: share a single token.
    token = resource.prop('token')
예제 #11
0
class CheckType(resource.Resource):
    base_path = 'check_types'
    resources_key = 'values'
    service = monitoring_service.MonitoringService()

    # capabilities
    allow_list = True
    allow_retrieve = True

    # Properties
    #: The category the check is in. Valid values are:
    #: ``agent`` or ``remote``.
    category = resource.prop('category')
    #: Check type fields. *Type: list*
    fields = resource.prop('fields', type=list)
    #: A friendly label
    name = resource.prop('id')
    #: Platforms on which an agent check type is supported. This is advisory
    #: information only. The check may still work on other platforms,
    #: or report that check execution failed at runtime.
    supported_platforms = resource.prop('supported_platforms')
    #: The name of the supported check type. Valid values are:
    #: ``agent`` or ``remote``.
    type = resource.prop('type')

    def targets(self, session, entity_id):
        """Lists agent check type targets for an entity

        Agent check types can gather data for a related set of target devices
        on the server where the agent is installed. Not every check type has a
        configurable target; currently supported check types with targets are:
        `agent.filesystem`, `agent.disk`, `agent.network`, and `agent.plugin`.

        :param entity_id: Target entity id where the agent is installed
        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :returns: ``list``
        """
        url = utils.urljoin('entities', entity_id, 'agent', 'check_types',
                            self.id, 'targets')
        resp = session.get(url, endpoint_filter=self.service).json()
        return resp['values']
예제 #12
0
class Agent(resource.Resource):
    base_path = 'agents'
    resources_key = 'values'
    service = monitoring_service.MonitoringService()

    # capabilities
    allow_list = True
    allow_retrieve = True

    # Properties
    #: User specified strings that are a maximum of 255 characters and
    #: can contain letters, numbers, dashes (-) and dots (.). If you used
    #: the Setup wizard to install and configure the agent on your host server,
    #: the ID for your agent is the fully qualified domain name (FQDN) of the
    #: host on which the agent is installed.
    id = resource.prop('id')
    #: Agent last connection time to a monitoring zone. If an agent does not
    #: connect to the account for 30 days, the agent is automatically deleted.
    #: Time is shown in Coordinated Universal Time (UTC) as the number
    #: of milliseconds that have elapsed since January 1, 1970. *Type: int*
    last_connected_at = resource.prop('last_connected', type=int)

    def connections(self, session):
        """List currently active connections for the agent

        Agents are connected to three monitoring zones
        when operating normally.

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :returns: ``list``
        """
        url = utils.urljoin(self.base_path, self.id, 'connections')
        resp = session.get(url, endpoint_filter=self.service).json()
        return resp['values']

    def host_info_types(self, session):
        """List the types of host info data supported by the agent

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :returns: ``list``
        """
        url = utils.urljoin(self.base_path, self.id, 'host_info_types')
        resp = session.get(url, endpoint_filter=self.service).json()
        return resp['types']

    def host_cpus(self, session):
        """Get information about the host CPUs

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :returns: ``list``
        """
        url = utils.urljoin(self.base_path, self.id, 'host_info', 'cpus')
        resp = session.get(url, endpoint_filter=self.service).json()
        return resp['info']

    def host_disks(self, session):
        """Get information about the host disks

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :returns: ``list``
        """
        url = utils.urljoin(self.base_path, self.id, 'host_info', 'disks')
        resp = session.get(url, endpoint_filter=self.service).json()
        return resp['info']

    def host_filesystems(self, session):
        """Get information about the host filesystems

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :returns: ``list``
        """
        url = utils.urljoin(self.base_path, self.id, 'host_info',
                            'filesystems')
        resp = session.get(url, endpoint_filter=self.service).json()
        return resp['info']

    def host_memory(self, session):
        """Get information about the host memory use

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :returns: ``list``
        """
        url = utils.urljoin(self.base_path, self.id, 'host_info', 'memory')
        resp = session.get(url, endpoint_filter=self.service).json()
        return resp['info']

    def host_nics(self, session):
        """Get information about the host network interfaces

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :returns: ``list``
        """
        url = utils.urljoin(self.base_path, self.id, 'host_info',
                            'network_interfaces')
        resp = session.get(url, endpoint_filter=self.service).json()
        return resp['info']

    def host_processes(self, session):
        """Get information about the host running processes

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :returns: ``list``
        """
        url = utils.urljoin(self.base_path, self.id, 'host_info', 'processes')
        resp = session.get(url, endpoint_filter=self.service).json()
        return resp['info']

    def host_system(self, session):
        """Get system information about the host

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :returns: ``list``
        """
        url = utils.urljoin(self.base_path, self.id, 'host_info', 'system')
        resp = session.get(url, endpoint_filter=self.service).json()
        return resp['info']

    def host_users(self, session):
        """Get information on users who are logged into the host

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :returns: ``list``
        """
        url = utils.urljoin(self.base_path, self.id, 'host_info', 'who')
        resp = session.get(url, endpoint_filter=self.service).json()
        return resp['info']
예제 #13
0
class Entity(resource.Resource):
    base_path = 'entities'
    resources_key = 'values'
    service = monitoring_service.MonitoringService()

    # capabilities
    allow_create = True
    allow_delete = True
    allow_list = True
    allow_retrieve = True
    allow_update = True

    # Properties
    #: List of active suppressions. *Type: list*
    active_suppressions = resource.prop('active_suppressions', type=list)
    #: Agent to which this entity is bound
    agent_id = resource.prop('agent_id')
    #: Creation timestamp.
    #: Time is shown in Coordinated Universal Time (UTC) as the number
    #: of milliseconds that have elapsed since January 1, 1970. *Type: int*
    created_at = resource.prop('created_at', type=int)
    #: Dictionary of IP addresses that can be referenced by
    #: checks on this entity. *Type: dict*
    ip_addresses = resource.prop('ip_addresses', type=dict)
    #: Indicates if this entity is managed
    #: by Rackspace Managed Cloud. *Type: bool*
    is_managed = resource.prop('managed', type=format.BoolStr)
    #: Arbitrary key/value pairs. *Type: dict*
    metadata = resource.prop('metadata', type=dict)
    #: A friendly label for the entity
    name = resource.prop('label')
    #: List of scheduled suppressions. *Type: list*
    scheduled_suppressions = resource.prop('scheduled_suppressions', type=list)
    #: Update timestamp.
    #: Time is shown in Coordinated Universal Time (UTC) as the number
    #: of milliseconds that have elapsed since January 1, 1970. *Type: int*
    updated_at = resource.prop('updated_at', type=int)
    #: The Rackspace Cloud identifier of this entity.
    #: Only applies to Rackspace Cloud servers.
    uri = resource.prop('uri')

    def alarm_changelog(self, session):
        """Return alarm changelog for the entity

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :returns: ``list``
        """
        url = utils.urljoin('changelogs', 'alarms?entityId=' + self.id)
        resp = session.get(url, endpoint_filter=self.service).json()
        return resp['values']

    def test_alarm(self, session, check_data, criteria):
        """Test an alarm

        Post alarm criteria and alarm data to test whether the alarm criteria
        is valid and to show how the alarm state is evaluated.

        The response not only provides the final evaluated state, but also
        includes all state transitions noticed during the calculation.
        You need to provide one or more observations.

        An observation consists of a set of metrics from a single data center.
        A group of observations consist of a set of metrics from more than one
        data center. When you test an alarm, you provide a list of check data,
        which you can retrieve from a test check operation.

        :param check_data: Metrics to check.
        :param criteria: The alarm DSL for describing alerting conditions.
        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :returns: ``list``
        """
        body = {"criteria": criteria, "check_data": check_data}
        url = utils.urljoin(self.base_path, self.id, 'test-alarm')
        return session.post(url, service=self.service, json=body).body

    def test_new_check(self, session, attributes):
        """Test a new check

        This operation causes Rackspace Cloud Monitoring to attempt to run the
        check on the specified monitoring zones and return the results.
        It allows you to test the check parameters in a single step before the
        check is actually created in the system.

        For the `remote.http` this call also includes debug information and the
        response body. Note: Only the first 512KB of the response body is read.
        If the response body is longer, it is truncated to 512KB.

        It requires a valid set of attributes from the checks attributes table.
        For a tutorial on creating some basic checks, see "Create checks" in
        the "Rackspace Cloud Monitoring Getting Started Guide".

        You can copy the results of a test check response and paste it directly
        into a test alarm.

        :param attributes: Valid set of attributes for check creation.
        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :returns: ``list``
        """
        url = utils.urljoin(self.base_path, self.id, 'test-check')
        return session.post(url, service=self.service, json=attributes).body
예제 #14
0
class Check(resource.Resource):
    base_path = '/entities/%(entity_id)s/checks'
    resources_key = 'values'
    service = monitoring_service.MonitoringService()

    # capabilities
    allow_create = True
    allow_delete = True
    allow_list = True
    allow_retrieve = True
    allow_update = True

    # Properties
    #: List of active suppressions. *Type: list*
    active_suppressions = resource.prop('active_suppressions', type=list)
    #: Creation timestamp.
    #: Time is shown in Coordinated Universal Time (UTC) as the number
    #: of milliseconds that have elapsed since January 1, 1970. *Type: int*
    created_at = resource.prop('created_at', type=int)
    #: Details specific to the check. *Type: dict*
    details = resource.prop('details', type=dict)
    #: The ID of the entity
    entity_id = resource.prop('entity_id')
    #: The period in seconds for a check. The value must be greater than
    #: the minimum period set on your account. *Type: int*
    frequency = resource.prop('period', type=int)
    #: Disables the check. *Type: bool*
    is_disabled = resource.prop('disabled', type=format.BoolStr)
    #: Arbitrary key/value pairs. *Type: dict*
    metadata = resource.prop('metadata', type=dict)
    #: List of monitoring zones to poll from. *Type: list*
    #: Note: This argument is only required for remote (non-agent) checks.
    monitoring_zones = resource.prop('monitoring_zones_poll', type=list)
    #: A friendly label for a check
    name = resource.prop('label')
    #: List of scheduled suppressions. *Type: list*
    scheduled_suppressions = resource.prop('scheduled_suppressions', type=list)
    #: A key in the entity's ip_addresses hash used to resolve this check to
    #: an IP address. Mutually exclusive with `target_hostname`.
    target_alias = resource.prop('target_alias')
    #: The hostname this check should target.
    #: Mutually exclusive with `target_alias`.
    target_hostname = resource.prop('target_hostname')
    #: Determines how to resolve the check target.
    target_resolver = resource.prop('target_resolver')
    #: The timeout in seconds for a check.
    #: This has to be less than the frequency. *Type: int*
    timeout = resource.prop('timeout', type=int)
    #: The type of check
    type_id = resource.prop('type')
    #: Update timestamp.
    #: Time is shown in Coordinated Universal Time (UTC) as the number
    #: of milliseconds that have elapsed since January 1, 1970. *Type: int*
    updated_at = resource.prop('updated_at', type=int)

    def metrics(self, session):
        """List metrics for the check

        This operation returns a response body that lists the metrics
        associated with your check. A single check usually generates several
        metrics. For example, http checks generate the following metrics:
        `bytes`, `code`, `duration`, `truncated`, `tt_connect`, `tt_firstbyte`.

        Metrics generated by remote checks are generated for each
        monitoring zone where the check is issued.

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :returns: ``list``
        """
        url = utils.urljoin('entities', self.entity_id, 'checks', self.id,
                            'metrics')
        resp = session.get(url, endpoint_filter=self.service).json()
        return resp['values']

    def test(self, session):
        """Test an existing check

        This operation does NOT cause the already-created check to be run,
        but rather creates a duplicate check with the same parameters as the
        original, and performs the test using that. You can copy the results of
        a test check response and paste it directly into a test alarm.

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :returns: ``list``
        """
        url = utils.urljoin('entities', self.entity_id, 'checks', self.id,
                            'test')
        resp = session.get(url, endpoint_filter=self.service).json()
        return resp