puppetdb

package module
v0.0.0-...-ce1d6af Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

README

go-puppetdb

An API client interface for PuppetDB

Please note that there since I wrote this, there is now a PuppetDB client implementation by Ken Barber from Puppet that you can also choose to use: https://github.com/kbarber/puppetdb-client-go

Background

Package contains interface to PuppetDB v3 API. Interface is still work in progress and does not cover the entire API.

Installation

Run go get github.com/akira/go-puppetdb.

Usage

import (
  "github.com/akira/go-puppetdb"
)

Create a Client with PuppetDB Hostname:

// second parameter enables verbose output
client := puppetdb.NewClient("localhost", 8080, true)

resp, err := client.Nodes()
...
resp, err := client.NodeFacts("node123")
...

It's also possible to use tls

client := puppetdb.NewClientSSL("puppet", 8081,"key.pem", "cert.pem", "ca.pem", true)

resp, err := client.Nodes()
...
resp, err := client.NodeFacts("node123")
...

It's also possible to query the puppet master services api now

client := puppetdb.NewClientSSLMaster("puppet", 8081,"key.pem", "cert.pem", "ca.pem", true)
resp, err := client.Profiler()

...

It's also possible to update/delete/view certificates

client := puppetdb.NewClientSSLMaster("puppet", 8081,"key.pem", "cert.pem", "ca.pem", true)
_, err, code := p.PuppetCertificateUpdateState("certname", "revoked")
err, code := p.PuppetCertificateDelete("certname")
certs, err := p.PuppetCertificates()
cert, err := p.PuppetCertificate("certname")
...
...

Queries can be represented as an array of strings and turned into JSON:

query, err := puppetdb.QueryToJSON([]string{"=", "report", "aef00"})
resp, res_err := client.Events(query, nil)

Contributors

Malte Krupa (temal-)

Will Roberts (willroberts)

Daniel Selans (dselans)

Tim eyzermans (negast)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func QueryToJSON

func QueryToJSON(query interface{}) (result string, err error)

QueryToJSON Converts a query to json.

Types

type Client

type Client struct {
	BaseURL string
	Cert    string
	Key     string
	// contains filtered or unexported fields
}

Client This represents a connection to your puppetdb instance

func NewClient

func NewClient(host string, port int, verbose bool) *Client

NewClient returns a http connection for your puppetdb instance.

func NewClientSSL

func NewClientSSL(host string, port int, key string, cert string, ca string, verbose bool) *Client

NewClientSSL returns a https connection for your puppetdb instance.

func NewClientSSLInsecure

func NewClientSSLInsecure(host string, port int, verbose bool) *Client

NewClientSSLInsecure returns a https connection for your puppetdb instance but trusts self signed certificates.

func NewClientTimeout

func NewClientTimeout(host string, port int, verbose bool, timeout int) *Client

NewClientTimeout returns a http connection for your puppetdb instance with a timeout.

func NewClientTimeoutSSL

func NewClientTimeoutSSL(host string, port int, key string, cert string, ca string, verbose bool, timeout int) *Client

NewClientTimeoutSSL returns a http connection for your puppetdb instance with a timeout and ssl configured.

func NewClientURL

func NewClientURL(url *url.URL, verbose bool) *Client

NewClientURL returns a http connection for your puppetdb instance.

func (*Client) EventCounts

func (c *Client) EventCounts(query string, summarizeBy string, extraParams map[string]string) ([]EventCountJSON, error)

EventCounts Returns the even counts

func (*Client) Events

func (c *Client) Events(query string, extraParams map[string]string) ([]EventJSON, error)

Events returns the events

func (*Client) FactNames

func (c *Client) FactNames() ([]string, error)

FactNames Gets all the fact names

func (*Client) FactPerNode

func (c *Client) FactPerNode(fact string) ([]FactJSON, error)

FactPerNode Gets all nodes values for a specified fact.

func (*Client) Get

func (c *Client) Get(v interface{}, path string, params map[string]string) error

Get gets the given url and retruns the result. In form of the given interface.

func (*Client) GetFacts

func (c *Client) GetFacts(path string) ([]FactJSON, error)

GetFacts returns an array of Json facts and returns them. It now uses gabs array because json value is not consistent.

func (*Client) Metric

func (c *Client) Metric(v interface{}, metric string) error

Metric returns a metric

func (*Client) MetricNumNodes

func (c *Client) MetricNumNodes() (result float64, err error)

MetricNumResources Gets the number of nodes

func (*Client) MetricNumResources

func (c *Client) MetricNumResources() (result float64, err error)

MetricNumResources Gets the number of resources

func (*Client) MetricResourcesPerNode

func (c *Client) MetricResourcesPerNode() (result float64, err error)

MetricResourcesPerNode Gets the average resources per node

func (*Client) NodeFacts

func (c *Client) NodeFacts(node string) ([]FactJSON, error)

NodeFacts Gets all the facts for a specified node.

func (*Client) Nodes

func (c *Client) Nodes() ([]NodeJSON, error)

Nodes Polls the nodes api of your puppetdb and returns the results in form of the NodeJSON type.

func (*Client) PuppetdbVersion

func (c *Client) PuppetdbVersion() (Version, error)

PuppetdbVersion gets the specified puppetdb version.

func (*Client) ReportByHash

func (c *Client) ReportByHash(hash string) ([]ReportJSON, error)

ReportByHash Gets the report for this specific hash

func (*Client) Reports

func (c *Client) Reports(query string, extraParams map[string]string) ([]ReportJSON, error)

Reports Gets the reports with the specified querry.

func (*Client) Resources

func (c *Client) Resources(query string, extraParams map[string]string) ([]Resource, error)

Resources will fetch resources from /resources/ in the puppetdb api

type ClientMaster

type ClientMaster struct {
	BaseURL string
	Cert    string
	Key     string
	// contains filtered or unexported fields
}

func NewClientSSLInsecureMaster

func NewClientSSLInsecureMaster(host string, port int, verbose bool) *ClientMaster

NewClientSSLInsecure returns a https connection for your puppetdb instance but trusts self signed certificates.

func NewClientSSLMaster

func NewClientSSLMaster(host string, port int, key string, cert string, ca string, verbose bool) *ClientMaster

NewClientSSL gets a new client with ssl certs enabled

func (*ClientMaster) Delete

func (c *ClientMaster) Delete(path string) (error, int)

Delete request to the given url and returns the result code

func (*ClientMaster) Get

func (c *ClientMaster) Get(v interface{}, path string) error

Get gets the given url and retruns the result. In form of the given interface.

func (*ClientMaster) Jruby

func (c *ClientMaster) Jruby() (JrubyMetrics, error)

Jruby returns a jruby metrics object

func (*ClientMaster) Master

func (c *ClientMaster) Master() (MasterMetrics, error)

Master returns a master metrics object

func (*ClientMaster) Profiler

func (c *ClientMaster) Profiler() (Profiler, error)

profiler returns a profiler metrics object

func (*ClientMaster) PuppetCertificate

func (c *ClientMaster) PuppetCertificate(certname string) (PuppetCertificate, error)

PuppetCertificate returns a single entry of a puppet certificate

func (*ClientMaster) PuppetCertificateDelete

func (c *ClientMaster) PuppetCertificateDelete(certname string) (error, int)

PuppetCertificateDelete deletes a certificate entry

func (*ClientMaster) PuppetCertificateUpdateState

func (c *ClientMaster) PuppetCertificateUpdateState(certname string, state string) (PuppetCertificateState, error, int)

PuppetCertificateUpdateStatereturns a single entry of a puppet certificate

func (*ClientMaster) PuppetCertificates

func (c *ClientMaster) PuppetCertificates() ([]PuppetCertificate, error)

PuppetCertificatesreturns an array of puppet certificates

func (*ClientMaster) Put

func (c *ClientMaster) Put(v interface{}, path string, values interface{}) (error, int)

Put request to the given url and returns the status code

func (*ClientMaster) Service

func (c *ClientMaster) Service() (ServiceMetrics, error)

Master returns a master metrics object

type EventCountJSON

type EventCountJSON struct {
	SubjectType string            `json:"subject-type"`
	Subject     map[string]string `json:"subject"`
	Failure     int64             `json:"failures"`
	Successes   int64             `json:"successes"`
	Noops       int64             `json:"noops"`
	Skips       int64             `json:"skips"`
}

EventCountJSON A json object holding the results of a query to the eventcount api

type EventJSON

type EventJSON struct {
	CertName          string `json:"certname"`
	OldValue          string `json:"old-value"`
	Property          string `json:"property"`
	Timestamp         string `json:"timestamp"`
	ResourceType      string `json:"resource-typ"`
	ResourceTitle     string `json:"resource-title"`
	NewValue          string `json:"new-value"`
	Message           string `json:"message"`
	Report            string `json:"report"`
	Status            string `json:"status"`
	File              string `json:"file"`
	ContainmentPath   string `json:"containment-path"`
	ContainmentClass  string `json:"containing-class"`
	RunStartTime      string `json:"run-start-time"`
	RunEndTime        string `json:"run-end-time"`
	ReportReceiveTime string `json:"report-receive-time"`
}

EventJSON A json object holding the results of a query to the event api.

type FactJSON

type FactJSON struct {
	CertName    string          `json:"certname"`
	Environment string          `json:"environment"`
	Name        string          `json:"name"`
	Value       *gabs.Container `json:"value"`
}

FactJSON A json object holding the results of a query to the facts api.

type JrubyBorrowedInstance

type JrubyBorrowedInstance struct {
	Time          int                          `json:"time"`
	DurationMilis int                          `json:"duration-millis"`
	Reason        *JrubyBorrowedInstanceReason `json:"reason"`
}

JrubyBorrowedInstance holds metrics for jruby

type JrubyBorrowedInstanceReason

type JrubyBorrowedInstanceReason struct {
	Request *JrubyBorrowedInstanceReasonRequest `json:"request"`
}

JrubyBorrowedInstanceReason holds metrics for jruby

type JrubyBorrowedInstanceReasonRequest

type JrubyBorrowedInstanceReasonRequest struct {
	Uri     string `json:"uri"`
	Method  string `json:"request-method"`
	RouteId string `json:"route-id"`
}

JrubyBorrowedInstanceReasonRequest holds metrics for jruby

type JrubyExperimental

type JrubyExperimental struct {
	JrubyPoolLockStatus *JrubyPoolLockStatus      `json:"jruby-pool-lock-status"`
	Metrics             *JrubyExperimentalMetrics `json:"metrics"`
}

JrubyExperimental is a struct that holds the array of metrics

type JrubyExperimentalMetrics

type JrubyExperimentalMetrics struct {
	AverageLockWaitTime     int                      `json:"average-lock-wait-time"`
	NumFreeJrubies          int                      `json:"num-free-jrubies"`
	BorrowCount             int                      `json:"borrow-count"`
	AverageRequestedJrubies float64                  `json:"average-requested-jrubies"`
	BorrowTimeoutCount      int                      `json:"borrow-timeout-count"`
	ReturnCount             int                      `json:"return-count"`
	BorrowRetryCount        int                      `json:"borrow-retry-count"`
	BorrowedInstances       *[]JrubyBorrowedInstance `json:"borrowed-instances"`
	AverageBorrowTime       int                      `json:"average-borrow-time"`
	NumJrubies              int                      `json:"num-jrubies"`
	RequestedCount          int                      `json:"requested-count"`
	QueueLimitHitRate       float64                  `json:"queue-limit-hit-rate"`
	AverageLockHeldTime     int                      `json:"average-lock-held-time"`
	QueueLimitHitCount      int                      `json:"queue-limit-hit-count"`
	AverageFreeJrubies      float64                  `json:"average-free-jrubies"`
	NumPoolLocks            int                      `json:"num-pool-locks"`
	AverageWaitTime         int                      `json:"average-wait-time"`
}

JrubyExperimentalMetrics holds metrics for jruby

type JrubyMetrics

type JrubyMetrics struct {
	Version      string       `json:"service_version"`
	StateVersion int          `json:"service_status_version"`
	DetailLevel  string       `json:"detail_level"`
	State        string       `json:"state"`
	Status       *JrubyStatus `json:"status"`
}

JrubyMetrics is a struct that holds the data for the jruby metrics

type JrubyPoolLockStatus

type JrubyPoolLockStatus struct {
	State      string `json:"current-state"`
	ChangeTime string `json:"last-change-time"`
}

JrubyPoolLockStatus holds metrics for jruby

type JrubyStatus

type JrubyStatus struct {
	Experimental *JrubyExperimental `json:"experimental"`
}

JrubyStatus is a struct that the experimental json which holds the correct arrays

type MasterExperimental

type MasterExperimental struct {
	HttpMetrics       *[]MasterHttpMetric       `json:"http-metrics"`
	HttpClientMetrics *[]MasterHttpClientMetric `json:"http-client-metrics"`
}

MasterExperimental is a struct that holds the array of metrics

type MasterHttpClientMetric

type MasterHttpClientMetric struct {
	MetricName string    `json:"metric-name"`
	MetricId   *[]string `json:"metric-id"`
	Count      int       `json:"count"`
	Mean       int       `json:"mean"`
	Aggregate  int       `json:"aggregate"`
}

MasterHttpClientMetric is a struct that holds master data

type MasterHttpMetric

type MasterHttpMetric struct {
	RouteId   string `json:"route-id"`
	Count     int    `json:"count"`
	Mean      int    `json:"mean"`
	Aggregate int    `json:"aggregate"`
}

MasterHttpMetric is a struct that holds master data

type MasterMetrics

type MasterMetrics struct {
	Version      string        `json:"service_version"`
	StateVersion int           `json:"service_status_version"`
	DetailLevel  string        `json:"detail_level"`
	State        string        `json:"state"`
	Status       *MasterStatus `json:"status"`
}

MasterMetrics holds metrics for jruby

type MasterStatus

type MasterStatus struct {
	Experimental *MasterExperimental `json:"experimental"`
}

MasterStatus is a struct that the experimental json which holds the correct arrays

type NodeJSON

type NodeJSON struct {
	Certname                     string `json:"certname"`
	Deactivated                  string `json:"deactivated"`
	CatalogTimestamp             string `json:"catalog_timestamp"`
	FactsTimestamp               string `json:"facts_timestamp"`
	CatalogEnvironment           string `json:"catalog_environment"`
	FactsEnvironment             string `json:"facts_environment"`
	LatestReportHash             string `json:"latest_report_hash"`
	CachedCatalogStatus          string `json:"cached_catalog_status"`
	ReportEnvironment            string `json:"report_environment"`
	ReportTimestamp              string `json:"report_timestamp"`
	LatestReportCorrectiveChange string `json:"latest_report_corrective_change"`
	LatestReportNoop             bool   `json:"latest_report_noop"`
	LatestReportNoopPending      bool   `json:"latest_report_noop_pending"`
	Expired                      string `json:"expired"`
	LatestReportJobID            string `json:"latest_report_job_id"`
	LatestReportStatus           string `json:"latest_report_status"`
}

NodeJSON A json object holding the results of query to the node api.

type Profiler

type Profiler struct {
	Version      string          `json:"service_version"`
	StateVersion int             `json:"service_status_version"`
	DetailLevel  string          `json:"detail_level"`
	State        string          `json:"state"`
	Status       *ProfilerStatus `json:"status"`
}

Profiler is a struct that holds the profiler metrics for the puppet master

type ProfilerCatalogMetric

type ProfilerCatalogMetric struct {
	Metric    string `json:"metric"`
	Count     int    `json:"count"`
	Mean      int    `json:"mean"`
	Aggregate int    `json:"aggregate"`
}

ProfilerCatalogMetric is a struct that holds the data for a single profiler catalog metric

type ProfilerExperimental

type ProfilerExperimental struct {
	FunctionMetrics *[]ProfilerFunctionMetric `json:"function-metrics"`
	ResourceMetrics *[]ProfilerResourceMetric `json:"resource-metrics"`
	CatalogMetrics  *[]ProfilerCatalogMetric  `json:"catalog-metrics"`
	PuppetdbMetrics *[]ProfilerCatalogMetric  `json:"puppetdb-metrics"`
}

ProfilerExperimental is a struct that holds the array of metrics

type ProfilerFunctionMetric

type ProfilerFunctionMetric struct {
	Function  string `json:"function"`
	Count     int    `json:"count"`
	Mean      int    `json:"mean"`
	Aggregate int    `json:"aggregate"`
}

ProfilerFunctionMetric is a struct that holds the data for a single profiler function metric

type ProfilerResourceMetric

type ProfilerResourceMetric struct {
	Resource  string `json:"resource"`
	Count     int    `json:"count"`
	Mean      int    `json:"mean"`
	Aggregate int    `json:"aggregate"`
}

ProfilerFunctionMetric is a struct that holds the data for a single profiler catalog metric

type ProfilerStatus

type ProfilerStatus struct {
	Experimental *ProfilerExperimental `json:"experimental"`
}

ProfilerStatus is a struct that the experimental json which holds the correct arrays

type PuppetCertificate

type PuppetCertificate struct {
	Name            string                       `json:"name"`
	State           string                       `json:"state"`
	DNSAltNames     []string                     `json:"dns_alt_names"`
	SubjectAltNames []string                     `json:"subject_alt_names"`
	Fingerprint     string                       `json:"fingerprint"`
	Fingerprints    PuppetCertificateFingerPrint `json:"fingerprints"`
}

PuppetCertificate is a struct that holds data for a puppet certificate entry

type PuppetCertificateFingerPrint

type PuppetCertificateFingerPrint struct {
	SHA1    string `json:"SHA1"`
	SHA256  string `json:"SHA256"`
	SHA512  string `json:"SHA512"`
	Default string `json:"default"`
}

PuppetCertificateFingerprint is a struct that holds data for a puppet certificate entry's fingerprint

type PuppetCertificateState

type PuppetCertificateState struct {
	DesiredState string `json:"desired_state"`
}

PuppetCertificateState is a struct that holds data for a puppet certificate state

type PuppetReportLog

type PuppetReportLog struct {
	Href string                        `json:"href"`
	Data []PuppetReportMetricsLogEntry `json:"data"`
}

type PuppetReportMetrics

type PuppetReportMetrics struct {
	Href string                         `json:"href"`
	Data []PuppetReportMetricsDataEntry `json:"data"`
}

type PuppetReportMetricsDataEntry

type PuppetReportMetricsDataEntry struct {
	Name     string  `json:"name"`
	Value    float64 `json:"value"`
	Category string  `json:"category"`
}

type PuppetReportMetricsLogEntry

type PuppetReportMetricsLogEntry struct {
	NewValue string   `json:"new_value"`
	Property string   `json:"property"`
	File     string   `json:"file"`
	Line     string   `json:"line"`
	Tags     []string `json:"tags"`
	Time     string   `json:"time"`
	Level    string   `json:"level"`
	Source   string   `json:"source"`
	Message  string   `json:"message"`
}

type PuppetReportResource

type PuppetReportResource struct {
	Href string `json:"href"`
}

type ReportJSON

type ReportJSON struct {
	CertName             string               `json:"certname"`
	PuppetVersion        string               `json:"puppet_version"`
	Value                string               `json:"value"`
	Hash                 string               `json:"hash"`
	ReportFormat         int64                `json:"report_format"`
	ConfigurationVersion string               `json:"configuration_version"`
	CatalogUUID          string               `json:"catalog_uuid"`
	TransactionUUID      string               `json:"transaction_uuid"`
	StartTime            string               `json:"start_time"`
	EndTime              string               `json:"end_time"`
	ReceiveTime          string               `json:"receive_time"`
	Noop                 bool                 `json:"noop"`
	Producer             string               `json:"producer"`
	CorrectiveChange     string               `json:"corrective_change"`
	Logs                 PuppetReportLog      `json:"logs"`
	ProducerTimestamp    string               `json:"producer_timestamp"`
	CachedCatalogStatus  string               `json:"cached_catalog_status"`
	ResourceEvents       PuppetReportResource `json:"resource_events"`
	Status               string               `json:"Status"`
	Environment          string               `json:"Environment"`
	CodeID               string               `json:"code_id"`
	NoopPending          bool                 `json:"noop_pending"`
	Metrics              PuppetReportMetrics  `json:"metrics"`
}

ReportJSON A json abject holding the data for a query from the report api.

type Resource

type Resource struct {
	Paramaters map[string]interface{} `json:"parameters"`
	Line       int                    `json:"line,omitempty"`
	Exported   bool                   `json:"exported,omitempty"`
	Tags       []string               `json:"tags,omitempty"`
	Title      string                 `json:"title,omitempty"`
	Type       string                 `json:"type,omitempty"`
	Resource   string                 `json:"resource,omitempty"`
	Certname   string                 `json:"certname,omitempty"`
}

Resource contains information about a puppet resource.

type ServiceExperimental

type ServiceExperimental struct {
	JVMMetrics *ServiceJVMMetric `json:"jvm-metrics"`
}

ServiceExperimental is a struct that holds the array of metrics

type ServiceJVMMetric

type ServiceJVMMetric struct {
	CpuUsage        float64                     `json:"cpu-usage"`
	UptimeMs        int                         `json:"up-time-ms"`
	GCCpuUsage      float64                     `json:"gc-cpu-usage"`
	StartTimeMs     int                         `json:"start-time-ms"`
	Threading       *ServiceJVMMetricThreading  `json:"threading"`
	HeapMemory      *ServiceJVMMetricHeapMemory `json:"heap-memory"`
	GCStats         *ServiceJVMMetricGCStats    `json:"gc-stats"`
	FileDescriptors *ServiceJVMMetricFile       `json:"file-descriptors"`
	NonHeapMemory   *ServiceJVMMetricHeapMemory `json:"non-heap-memory"`
}

ServiceJVMMetric is a struct that holds metrics

type ServiceJVMMetricFile

type ServiceJVMMetricFile struct {
	Max  int `json:"max"`
	Used int `json:"used"`
}

ServiceJVMMetricFile is a struct that holds metrics

type ServiceJVMMetricGCStats

type ServiceJVMMetricGCStats struct {
	PSScavenge *ServiceJVMMetricPS `json:"PS Scavenge"`
	PSSweep    *ServiceJVMMetricPS `json:"PS MarkSweep"`
}

ServiceJVMMetricGCStats is a struct that holds metrics

type ServiceJVMMetricHeapMemory

type ServiceJVMMetricHeapMemory struct {
	Committed int `json:"committed"`
	Init      int `json:"init"`
	Max       int `json:"max"`
	Used      int `json:"used"`
}

ServiceJVMMetricHeapMemory is a struct that holds metrics

type ServiceJVMMetricLastInfo

type ServiceJVMMetricLastInfo struct {
	DurationMs int `json:"duration-ms"`
}

ServiceJVMMetricLastInfo is a struct that holds metrics

type ServiceJVMMetricPS

type ServiceJVMMetricPS struct {
	Count       int                       `json:"count"`
	TotalTimeMs int                       `json:"total-time-ms"`
	LastGCInfo  *ServiceJVMMetricLastInfo `json:"last-gc-info"`
}

ServiceJVMMetricPS is a struct that holds metrics

type ServiceJVMMetricThreading

type ServiceJVMMetricThreading struct {
	ThreadCount     int `json:"thread-count"`
	PeakThreadCount int `json:"peak-thread-count"`
}

ServiceJVMMetricThreading is a struct that holds metrics

type ServiceMetrics

type ServiceMetrics struct {
	Version      string         `json:"service_version"`
	StateVersion int            `json:"service_status_version"`
	DetailLevel  string         `json:"detail_level"`
	State        string         `json:"state"`
	Status       *ServiceStatus `json:"status"`
}

ServiceMetrics holds metrics for jruby

type ServiceStatus

type ServiceStatus struct {
	Experimental *ServiceExperimental `json:"experimental"`
}

ServiceStatus is a struct that the experimental json which holds the correct arrays

type ValueMetricJSON

type ValueMetricJSON struct {
	Value float64
}

ValueMetricJSON A simple structholding a float value.

type Version

type Version struct {
	Version string `json:"version"`
}

Version a simple struct holding the puppetdb version.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL