Table of contents
1.
Introduction
2.
Admin Commands Endpoint
2.1.
Request Format
2.2.
URL Parameters
2.3.
Admin Commands
2.3.1.
‘clean’ in Admin API Version 1
2.3.2.
‘delete’ in Admin API Version 1
3.
Archive Endpoint
3.1.
POST Archive
3.1.1.
Request Format
3.1.2.
URL Parameters
3.1.3.
Response Format
3.1.4.
Example
3.2.
GET Archive
3.2.1.
URL Parameters
3.2.2.
Response Format
3.2.3.
Example
4.
Summary-stats Endpoint
4.1.
Response Format
5.
Frequently Asked Questions
5.1.
What is Puppet?
5.2.
Do we need to change the port number in the request if we change the service's port number?
5.3.
What are puppet reports?
5.4.
Is Puppet a monitoring tool?
6.
Conclusion
Last Updated: Mar 27, 2024
Easy

Admin API version 1 in PuppetDB

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Hey Ninja, In this article, we will briefly discuss Puppet and look at Puppet admin API version 1 command endpoints. Puppet lets us generate reports and perform automation and configurations. In a broader sense, a Puppet is an automation tool, a configuration management program. The primary concept is to have a single central server with all important machine configuration information.

admin api v1 puppetdb

This article will discuss the various endpoints of the Admin API version 1 in PuppetDB. If you are interested in Puppet, you can also check out Ansible Vs Puppet and see the distinction between these two similar and popular tools.

Admin Commands Endpoint

We can use the Admin Commands Endpoint or /cmd endpoint to trigger PuppetDB maintenance operations or delete a node directly. Puppet processes Admin commands synchronously separate from other PuppetDB commands.

You must trigger the Admin command using POST like this:

POST /pdb/admin/v1/cmd
Puppet CN

Request Format

The POST request for the command endpoint must specify Content-Type: application/json and the body of this request will be:

{"command": "...",
 "version": 123,
 "payload": <json object>}


In the above code format, the parameters are as follows:

  • command: This is a string value that identifies the command
     
  • version: This field is for a JSON integer describing the version of the given command you are trying to invoke. It also indicates the version of the wire format to use for the command.
     
  • payload: This field must contain a valid JSON object of any type. It's up to the specific handler function to interpret that object.

URL Parameters

POST endpoint does not accept any parameters.

Admin Commands

There are two types of Admin Commands for the Admin API version 1. They are:

  • clean
     
  • delete
     

Let us now see a little more details about these two.

‘clean’ in Admin API Version 1

As the name suggests, we can use this command for cleanup in Admin API version 1. The structure of the command looks like this:

{"command" : "clean",
 "version" : 1,
 "payload" : [REQUESTED_OPERATION, ...]}


Here the valid entries for REQUESTED_OPERATIONS are "purge_nodes", "purge_reports", "expire_nodes", and “other”.

You can also specify a batch limit using "purge_nodes" that will restrict the maximum number of nodes purged to the specified value (for example, 25). Otherwise, the limit will be the node-purge-gc-batch-limit.

["purge_nodes" {"batch_limit" : 25}]


Response Format

The response type for this command is application/json, which will include the following JSON map:

{"ok": true}

 

Note: You can only run one maintenance operation at a time. If another maintenance operation is already in progress, the HTTP response status will be 409 (conflict) and include a map, as shown below. Due to this, Puppet will perform no additional maintenance. The msg and details may vary, but the kind will always be "conflict."

{"kind": "conflict",
 "msg": "Another cleanup is already in progress",
 "details": null}


Example

Below is the example for this Admin command

$ curl -X POST http://localhost:8080/pdb/admin/v1/cmd \
       -H 'Accept: myapplication/json' \
       -H 'Content-Type: myapplication/json' \
       -d '{"command": "clean",
            "version": 1,
            "payload": ["expire_nodes", "purge_nodes"]}'
{"ok": true}


‘delete’ in Admin API Version 1

In contrast to the "clean" command, you can use the "delete" command to trigger the deletion of all data associated with a certname immediately in Admin API version 1. The structure for this command looks like this:

{"command" : "delete",
 "version" : 1,
 "payload" : {"certname" : <string>}}


Note: The delete operation does not account for commands which may be in the command queue but not yet processed by PuppetDB. That may cause a node targeted for deletion to reappear when the command in the queue gets processed after running the deletion operation.

Response Format

Similar to “clean”, the response type for this command is application/json, which will include the following JSON map in Admin API version 1:

{"deleted": "certname"}


Example

Below is the example for the use of this Admin command using curl from localhost.

$ curl -X POST http://localhost:8080/pdb/admin/v1/cmd \
       -H 'Accept: myapplication/json' \
       -H 'Content-Type: myapplication/json' \
       -d '{"command": "delete",
            "version": 1,
            "payload": {"certname" : "node-1"}}'
{"deleted": "node-1"}

Archive Endpoint

You can use the Archive or /archive endpoint to import and export the PuppetDB archives. There are two separate ways in which you can use this endpoint.

  • POST /pdb/admin/v1/archive
     
  • GET /pdb/admin/v1/archive
     

We will now go into the details of these two endpoints.

POST Archive

We use the POST /pdb/admin/v1/archive endpoint to stream a PuppetDB archive into PuppetDB. 

Request Format

The request must be a multipart POST having Content-Type: multipart/mixed.

URL Parameters

This endpoint takes a single, required parameter; archive. The parameter is for the archive file you want to import to PuppetDB.

Note: This archive must contain a file named puppetdb-bak/metadata.json as its first entry in the tarfile with a key command_versions; that is, a JSON object mapping PuppetDB command names to their versions.

Response Format

The response type for this endpoint is also application/json, which will return a JSON map on completion.

{"ok": true}


Example

Below is the example for the POST /pdb/admin/v1/archive using curl from localhost

curl -X POST http://localhost:8080/pdb/admin/v1/archive \
    -F "archive=@myexample_archive.tgz"

{"ok": true}

GET Archive

We use the GET /pdb/admin/v1/archive endpoint to stream a tarred, gzipped backup archive of PuppetDB to our local machine.

URL Parameters

This endpoint takes a single, optional parameter; anonymization_profile. The parameter is for the level of anonymization on the archive files.

Response Format

The response for this endpoint will be an application/octet-stream, which returns a tar.gz archive.

Example

Below is the example for the POST /pdb/admin/v1/archive using curl from localhost:

curl -X GET http://localhost:8080/pdb/admin/v1/archive -o puppetdb-export.tgz

Summary-stats Endpoint

We can use the summary-stats or  /pdb/admin/v1/summary-stats endpoint to generate information about the use of Postgres in our PostgresDB installation. Although it can be independently functional, its primary purpose is to help resolve the diagnosis of support issues.

Response Format

The summary stats endpoint takes several keys as a JSON map in the response format. These include postgress statistics like table_usage, index_usage, and database_usage, as well as other keys like node_activity, fact_path_counts_by_depth, num_shared_value_path_combos, etc. which should be all in JSON format.

See the complete list of keys on the official documentation of the summary-stats endpoint.

Note: 

  • The summary-stats endpoint is considered experimental and may be changed or removed in future releases.
     
  • The summary-stats endpoint will execute many relatively expensive SQL commands against your database. 
     
  • It does not impede the performance of a running PDB instance a lot, but the request may take some time to complete.

Frequently Asked Questions

What is Puppet?

Puppet is a configuration management program. The main objective is to have a single central server with all important machine configuration information.

Do we need to change the port number in the request if we change the service's port number?

Yes, we need to specify the port number in the request if we change the service's port number.

What are puppet reports?

You can customize the built-in report processors in Puppet. By default, Puppet creates a report after applying a catalog that contains details about the Run, including events, log messages, resource statuses, metrics, and metadata. Each host transmits a YAML dump of its report.

Is Puppet a monitoring tool?

External services can use performance and status metrics from Puppet Server to track the health and performance of a server over time.

Conclusion

That concludes our article exploring the different aspects of the Admin API version 1 in PuppetDB. We went over three endpoints of the Admin API version 1: Archive Endpoint,  Admin Commands Endpoint, and Summary-stats Endpoint and their specifications. See more on Puppet: 

Why stop here? Also, practice data structures and algorithmsinterview questionsDBMScomputer networks, and operating systems to crack the interviews of big tech giants. Explore other fields like machine learningdeep learningcomputer vision, and big data. Also, check out Interview Experiences for different companies.

Happy learning!

Live masterclass