Example #1
0
def get_events(api_url=None, query='', verify=False, cert=list()):
    """
    Returns events

    :param api_url: Base PuppetDB API url
    :param query: Required. A JSON array of query predicates, in prefix form (the standard ["<OPERATOR>", "<FIELD>", "<VALUE>"] format), conforming to the format described below.
                    The query parameter is described by the following grammar:

                    query: [ {bool} {query}+ ] | [ "not" {query} ] | [ {match} {field} {value} ] | [ {inequality} {field} {value} ]
                    field:          FIELD (conforming to [Fields](#fields) specification below)
                    value:          string
                    bool:           "or" | "and"
                    match:          "=" | "~"
                    inequality:     ">" | ">=" | "<" | "<="
                    For example, for all events in the report with hash ‘38ff2aef3ffb7800fe85b322280ade2b867c8d27’, the JSON query structure would be:

                    ["=", "report", "38ff2aef3ffb7800fe85b322280ade2b867c8d27"]
                    To retrieve all of the events within a given time period:

                    ["and", ["<", "timestamp", "2011-01-01T12:01:00-03:00"],
                            [">", "timestamp", "2011-01-01T12:00:00-03:00"]]
                    To retrieve all of the ‘failure’ events for nodes named ‘foo.*’ and resources of type ‘Service’:

                    ["and", ["=", "status", "failure"],
                            ["~", "certname", "^foo\\."],
                            ["=", "resource-type", "Service"]]
                    To retrieve latest events that are tied to the class found in your update.pp file

                    ["and", ["=", "latest-report?", true],
                            ["~", "file", "update.pp"]]


    """
    return utils._make_api_request(api_url, '/events', verify, cert, params={'query': query})
Example #2
0
def get_reports(api_url=None, query='', verify=False, cert=list()):
    """
    Returns reports

    :param api_url: Base PuppetDB API url
    :param query: Required. A JSON array of query predicates, in prefix form. (The standard ["<OPERATOR>", "<FIELD>", "<VALUE>"] format.)

    Response
     [
      {
        "end-time": "2012-10-29T18:38:01.000Z",
        "puppet-version": "3.0.1",
        "receive-time": "2012-10-29T18:38:04.238Z",
        "configuration-version": "1351535883",
        "start-time": "2012-10-29T18:38:00.000Z",
        "hash": "bd899b1ee825ec1d2c671fe5541b5c8f4a783472",
        "certname": "foo.local",
        "report-format": 4,
        "transaction-uuid": "030c1717-f175-4644-b048-ac9ea328f221"
        },
      {
        "end-time": "2012-10-26T22:39:32.000Z",
        "puppet-version": "3.0.1",
        "receive-time": "2012-10-26T22:39:35.305Z",
        "configuration-version": "1351291174",
        "start-time": "2012-10-26T22:39:31.000Z",
        "hash": "cd4e5fd8846bac26d15d151664a40e0f2fa600b0",
        "certname": "foo.local",
        "report-format": 4,
        "transaction-uuid": null
        }
    ]
    """
    return utils._make_api_request(api_url, '/reports', verify, cert, params={'query': query})
Example #3
0
def get_facts(api_url=None, query={}, verify=False, cert=list()):
    """
    Returns info for all Nodes

    :param api_url: Base PuppetDB API url

    """
    return utils._make_api_request(api_url, '/nodes', verify, cert)
Example #4
0
def get_all_metric_names(api_url=None, verify=False, cert=list()):
    """
    Returns all available metric names

    :param api_url: Base PuppetDB API url

    """
    return utils._make_api_request(api_url, '/metrics/mbeans', verify, cert)
Example #5
0
def get_facts(api_url=None, query='', verify=False, cert=list()):
    """
    Returns facts

    :param api_url: Base PuppetDB API url

    """
    return utils._make_api_request(api_url, '/facts', verify, cert, params={'query': query})
Example #6
0
def get_resources_by_name(api_url=None, resource_name=None, verify=False, cert=list()):
    """
    Returns facts by name

    :param api_url: Base PuppetDB API url
    :param resource_name: Name of resource

    """
    return utils._make_api_request(api_url, '/resources/{0}'.format(resource_name), verify, cert)
Example #7
0
def get_metric(api_url=None, metric_name=None, verify=False, cert=list()):
    """
    Returns info for a Node

    :param api_url: Base PuppetDB API url
    :param metric_name: Name of metric

    """
    return utils._make_api_request(api_url, '/metrics/mbean/{0}'.format(metric_name), verify, cert)
Example #8
0
def get_catalog(api_url=None, node_name=None, verify=False, cert=list()):
    """
    Returns catalogs by node

    :param api_url: Base PuppetDB API url
    :param node_name: Name of node

    """
    return utils._make_api_request(api_url, '/catalogs/{0}'.format(node_name), verify, cert)
Example #9
0
def get_node_resources(api_url=None, node_name=None, verify=False, cert=list()):
    """
    Returns resources for a Node

    :param api_url: Base PuppetDB API url
    :param node_name: Name of node

    """
    return utils._make_api_request(api_url, '/nodes/{0}/resources'.format(node_name), verify, cert)
Example #10
0
def get_facts_by_name(api_url=None, fact_name=None, verify=False, cert=list()):
    """
    Returns facts by name

    :param api_url: Base PuppetDB API url
    :param fact_name: Name of fact

    """
    return utils._make_api_request(api_url, '/facts/{0}'.format(fact_name), verify, cert)
Example #11
0
def get_fact_names(api_url=None, verify=False, cert=list()):
    """
    Returns fact names

    :param api_url: Base PuppetDB API url

    Response
    [<fact>, <fact>, ..., <fact>, <fact>]
    """
    return utils._make_api_request(api_url, '/fact-names', verify, cert)
Example #12
0
def get_resources_by_name_and_value(api_url=None, resource_name=None, resource_value=None, verify=False, cert=list()):
    """
    Returns resources by name and value

    :param api_url: Base PuppetDB API url
    :param resource_name: Name of fact
    :param resource_value: Value of fact

    """
    return utils._make_api_request(api_url, '/resources/{0}/{1}'.format(resource_name, resource_value), verify, cert)
Example #13
0
def get_node_fact_by_name(api_url=None, node_name=None, fact_name=None, verify=False, cert=list()):
    """
    Returns specified fact for a Node

    :param api_url: Base PuppetDB API url
    :param node_name: Name of node
    :param fact_name: Name of fact

    """
    return utils._make_api_request(api_url, '/nodes/{0}/facts/{1}'.format(node_name,
        fact_name), verify, cert)
Example #14
0
def get_node_resource_by_type(api_url=None, node_name=None,
    type_name=None, verify=False, cert=list()):
    """
    Returns specified resource for a Node

    :param api_url: Base PuppetDB API url
    :param node_name: Name of node
    :param type_name: Type of resource

    """
    return utils._make_api_request(api_url, '/nodes/{0}/resources/{1}'.format(node_name,
        type_name), verify, cert)
Example #15
0
def get_version(api_url=None, verify=False, cert=list()):
    """
    Returns server version

    :param api_url: Base PuppetDB API url

    Response

    {
        {"version": "X.Y.Z"}
    }
    """
    return utils._make_api_request(api_url, '/version', verify, cert)
Example #16
0
def get_facts(api_url=None, query='', verify=False, cert=list()):
    """
    Returns facts

    :param api_url: Base PuppetDB API url
    :param query: Optional. A JSON array containing the query in prefix notation. If not provided, all results will be returned.

    Response
    [{"certname": "a.example.com", "name": "operatingsystem", "value": "Debian"},
    {"certname": "b.example.com", "name": "operatingsystem", "value": "RedHat"},
    {"certname": "c.example.com", "name": "operatingsystem", "value": "Darwin"}]
    """
    return utils._make_api_request(api_url, '/facts', verify, cert, params={'query': query})
Example #17
0
def get_facts_by_name_and_value(api_url=None, fact_name=None, fact_value=None, verify=False, cert=list()):
    """
    Returns facts by name and value

    :param api_url: Base PuppetDB API url
    :param fact_name: Name of fact
    :param fact_value: Value of fact

    Response
    [{"certname": "a.example.com", "name": "operatingsystem", "value": "Debian"},
    {"certname": "b.example.com", "name": "operatingsystem", "value": "Debian}]
    """
    return utils._make_api_request(api_url, '/facts/{0}/{1}'.format(fact_name, fact_value), verify, cert)
def get_aggregate_event_counts(api_url=None, query='', summarize_by='', count_by='', counts_filter='', distinct_resources='', verify=False, cert=list()):
    """
    Returns facts

    :param api_url: Base PuppetDB API url
    :param query: Required. A JSON array of query predicates in prefix form (["<OPERATOR>", "<FIELD>", "<VALUE>"]). This query is forwarded to the events endpoint - see there for additional documentation.
    :param summarize_by: Required. A string specifying which type of object you’d like to see counts for. Supported values are resource, containing-class, and certname.
    :param count_by: Optional. A string specifying what type of object is counted when building up the counts of successes, failures, noops, and skips. Supported values are resource (default) and certname.
    :param counts_filter: Optional. A JSON array of query predicates in the usual prefix form. This query is applied to the final event counts output. Supported operators are =, >, <, >=, and <=. Supported fields are failures, successes, noops, and skips.
    :param distinct_resources: Optional. (EXPERIMENTAL: it is possible that the behavior of this parameter may change in future releases.) This parameter is passed along to the event query - see there for additional documentation.

    Response Format

    {
        "successes": 2,
        "failures": 0,
        "noops": 0,
        "skips": 1,
        "total": 3
    }
    """
    return utils._make_api_request(api_url, '/aggregate-event-counts', verify, cert, params={'query': query,'summarize-by':summarize_by,'count-by':count_by,'counts-filter':counts_filter,'distinct_resources':distinct_resources})