puppetquery

package module
v0.0.0-...-651e7d1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2019 License: MIT Imports: 10 Imported by: 0

README

puppetquery

Query puppetdb sane and dependency free.

Build Status

LICENSE

BSD

documentation

package documentation at go.pkgdoc.org

quick usage

  • put URL to your puppetdb in $HOME/.config/puppetquery/config.ini with a line like url=http://localhost:8080

  • list names of all active puppet nodes by calling nq without parameters

  • list names of active puppet nodes having fact1=foo and fact2=bar (implicit and)

    nq fact1=foo fact2=bar

  • list all facts of a given hostname (nodename in puppet)

    nq -l hostname

  • show values of fact1 and fact2 for hosts having fact3=foo and fact4= bar, if fact1 and fact2 are set for this host

    nq -f fact1,fact2 fact3=foo fact4=bar

  • show values of fact1 and fact2 for specific host, if they exist

    nq -f fact1,fact2 fqdn=hostname.fully.qualified.domain.tld

build and install

install from package

Just install the package puppetquery.

build the package

Works like any other debian source package

  • Install build tools from debian via apt-get install devscripts fakeroot
  • Install build dependencies as reported with dpkg-checkbuilddeps
  • Run fakeroot debian/rules binary

Note: Please don't forget to increase the version number and adding your changes to the debian/changelog via dch -i before building a package you plan to release!

install from source

Install Go 1, either from source or with a prepackaged binary.

Then run

go get github.com/nightlyone/puppetquery
go get github.com/nightlyone/puppetquery/cmd/nq

List all active puppet nodes

$GOPATH/bin/nq

List all active puppet nodes have 2 processors and running Debian

$GOPATH/bin/nq processorcount=2 osfamily=Debian

LICENSE

BSD

documentation

contributing

Contributions are welcome. Please open an issue or send me a pull request for a dedicated branch. Make sure the git commit hooks show it works.

git commit hooks

enable commit hooks via

    cd .git ; rm -rf hooks; ln -s ../git-hooks hooks ; cd ..

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GlobalConfig = "/etc/puppetquery/config.ini"
	UserConfig   = ".config/puppetquery/config.ini"
)

Locations of site/global config and per user config.

View Source
var DefaultEndpoint = "http://localhost:8080"

Endpoint, if we didn't configure any

Functions

func QueryFacts

func QueryFacts(node string) (facts map[string]string, err error)

query facts api endpoint returning the list of facts for a node

func QueryNodes

func QueryNodes(query QueryString) (nodes []string, err error)

query node endpoint returning a list of nodes matching the query

Types

type HttpError

type HttpError struct {
	// contains filtered or unexported fields
}

func (HttpError) Error

func (e HttpError) Error() string

type QueryString

type QueryString []any

internal format to manage and massage Query

func ActiveNodes

func ActiveNodes() QueryString

Returns a query for active nodes only

func And

func And(left, right QueryString) QueryString

constructs and(left, right) from left and right

func BinOp

func BinOp(binop string, left, right QueryString) QueryString

returns Query <left> <binop> <right> and reduces left or right, if it contains binop already e.g. (a and b) and c becomes and(a,b,c)

func FactCompare

func FactCompare(name, op string, value any) QueryString

returns a fact comparison query

func Match

func Match(key string, value interface{}) QueryString

Match returns a query matching for existance of certain (key,value) pairs

func Not

func Not(tree QueryString) QueryString

returns Query "not" <tree> <binop> <right> and reduces not(not(tree)) to tree again

func Or

func Or(left, right QueryString) QueryString

constructs or(left, right) from left and right

func (*QueryString) ToJson

func (q *QueryString) ToJson() string

type Resource

type Resource struct {
	Certname   string                 `json:"certname"`
	Type       string                 `json:"type"`
	Title      string                 `json:"title"`
	Exported   bool                   `json:"exported"`
	Tags       []string               `json:"tags"`
	Sourcefile string                 `json:"sourcefile"`
	Sourceline int                    `json:"sourceline"`
	Parameters map[string]interface{} `json:"parameters"`
}

A Resource as returned by puppetdb resource endpoint

func CollectResources

func CollectResources(typ string, tags ...string) (resources []Resource, err error)

CollectResources delivers collected resources of typ matching all of the tags provided.

Directories

Path Synopsis
cmd
nq
puppet-naginator
The puppet-naginator command collects nagios_XXXX resources and writes them to stdout.
The puppet-naginator command collects nagios_XXXX resources and writes them to stdout.

Jump to

Keyboard shortcuts

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