|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""This module contains interfaces for all Report generation features of the |
| 3 | +REST API |
| 4 | +""" |
| 5 | +from .session import DynectSession |
| 6 | + |
| 7 | +__author__ = 'elarochelle' |
| 8 | +__all__ = ['get_check_permission', 'get_dnssec_timeline', 'get_qps', |
| 9 | + 'get_rttm_log', 'get_rttm_rrset', 'get_zone_notes'] |
| 10 | + |
| 11 | + |
| 12 | +def get_check_permission(permission, zone_name=None): |
| 13 | + """Returns a list of allowed and forbidden permissions for the currently |
| 14 | + logged in user based on the provided permissions array. |
| 15 | +
|
| 16 | + :param permission: A list of permissions to check for the current user. |
| 17 | + :param zone_name: The zone to check for specific permissions. |
| 18 | + :return: A :class:`dict` containing permission information. |
| 19 | + """ |
| 20 | + api_args = {'permission': permission} |
| 21 | + if zone_name is not None: |
| 22 | + api_args['zone_name'] = zone_name |
| 23 | + response = DynectSession.get_session().execute('/CheckPermissionReport/', |
| 24 | + 'POST', api_args) |
| 25 | + return response['data'] |
| 26 | + |
| 27 | + |
| 28 | +def get_dnssec_timeline(zone_name, start_ts=None, end_ts=None): |
| 29 | + """Generates a report of events for the :class:`DNSSEC` service |
| 30 | + attached to the specified zone has performed and has scheduled |
| 31 | + to perform. |
| 32 | +
|
| 33 | + :param zone_name: The name of the zone with DNSSEC service |
| 34 | + :param start_ts: UNIX timestamp identifying point in time for the |
| 35 | + report |
| 36 | + :param end_ts: UNIX timestamp indicating the end of the data range for |
| 37 | + the report |
| 38 | + :return: A :class:`dict` containing log report data |
| 39 | + """ |
| 40 | + api_args = {'zone': zone_name} |
| 41 | + if start_ts is not None: |
| 42 | + api_args['start_ts'] = start_ts |
| 43 | + if end_ts is not None: |
| 44 | + api_args['end_ts'] = end_ts |
| 45 | + response = DynectSession.get_session().execute('/DNSSECTimelineReport/', |
| 46 | + 'POST', api_args) |
| 47 | + return response['data'] |
| 48 | + |
| 49 | + |
| 50 | +def get_rttm_log(zone_name, fqdn, start_ts, end_ts): |
| 51 | + """Generates a report with information about changes to an existing |
| 52 | + RTTM service. |
| 53 | +
|
| 54 | + :param zone_name: The name of the zone |
| 55 | + :param fqdn: The FQDN where RTTM is attached |
| 56 | + :param start_ts: UNIX timestamp identifying point in time for the log |
| 57 | + report |
| 58 | + :param end_ts: UNIX timestamp indicating the end of the data range for |
| 59 | + the report |
| 60 | + :return: A :class:`dict` containing log report data |
| 61 | + """ |
| 62 | + api_args = {'zone': zone_name, |
| 63 | + 'fqdn': fqdn, |
| 64 | + 'start_ts': start_ts, |
| 65 | + 'end_ts': end_ts} |
| 66 | + response = DynectSession.get_session().execute('/RTTMLogReport/', |
| 67 | + 'POST', api_args) |
| 68 | + return response['data'] |
| 69 | + |
| 70 | + |
| 71 | +def get_rttm_rrset(zone_name, fqdn, ts): |
| 72 | + """Generates a report of regional response sets for this RTTM service |
| 73 | + at a given point in time. |
| 74 | +
|
| 75 | + :param zone_name: The name of the zone |
| 76 | + :param fqdn: The FQDN where RTTM is attached |
| 77 | + :param ts: UNIX timestamp identifying point in time for the report |
| 78 | + :return: A :class:`dict` containing rrset report data |
| 79 | + """ |
| 80 | + api_args = {'zone': zone_name, |
| 81 | + 'fqdn': fqdn, |
| 82 | + 'ts': ts} |
| 83 | + response = DynectSession.get_session().execute('/RTTMRRSetReport/', |
| 84 | + 'POST', api_args) |
| 85 | + return response['data'] |
| 86 | + |
| 87 | + |
| 88 | +def get_qps(start_ts, end_ts, breakdown=None, hosts=None, rrecs=None, |
| 89 | + zones = None): |
| 90 | + """Generates a report with information about Queries Per Second (QPS). |
| 91 | +
|
| 92 | + :param start_ts: UNIX timestamp identifying point in time for the QPS |
| 93 | + report |
| 94 | + :param end_ts: UNIX timestamp indicating the end of the data range for |
| 95 | + the report |
| 96 | + :param breakdown: By default, most data is aggregated together. |
| 97 | + Valid values ('hosts', 'rrecs', 'zones'). |
| 98 | + :param hosts: List of hosts to include in the report. |
| 99 | + :param rrecs: List of record types to include in report. |
| 100 | + :param zones: List of zones to include in report. |
| 101 | + :return: A :class:`str` with CSV data |
| 102 | + """ |
| 103 | + api_args = {'start_ts': start_ts, |
| 104 | + 'end_ts': end_ts} |
| 105 | + if breakdown is not None: |
| 106 | + api_args['breakdown'] = breakdown |
| 107 | + if hosts is not None: |
| 108 | + api_args['hosts'] = hosts |
| 109 | + if rrecs is not None: |
| 110 | + api_args['rrecs'] = rrecs |
| 111 | + if zones is not None: |
| 112 | + api_args['zones'] = zones |
| 113 | + response = DynectSession.get_session().execute('/QPSReport/', |
| 114 | + 'POST', api_args) |
| 115 | + return response['data'] |
| 116 | + |
| 117 | + |
| 118 | +def get_zone_notes(zone_name, offset=None, limit=None): |
| 119 | + """Generates a report containing the Zone Notes for given zone. |
| 120 | +
|
| 121 | + :param zone_name: The name of the zone |
| 122 | + :param offset: UNIX timestamp of the starting point at which to |
| 123 | + retrieve the notes |
| 124 | + :param limit: The maximum number of notes to be retrieved |
| 125 | + :return: A :class:`list` of :class:`dict` containing Zone Notes |
| 126 | + """ |
| 127 | + api_args = {'zone': zone_name} |
| 128 | + if offset: |
| 129 | + api_args['offset'] = offset |
| 130 | + if limit: |
| 131 | + api_args['limit'] = limit |
| 132 | + response = DynectSession.get_session().execute('/ZoneNoteReport/', |
| 133 | + 'POST', api_args) |
| 134 | + return response['data'] |
0 commit comments