Total Pageviews

Thursday, 8 July 2021

Peekaboo

 a Micro-service for exposing system's hardware information。

This is a re-factoring of the original Peekaboo to support gRPC and MTLS.

Usage

Usage: ./client [options] <resource> <address...>
  -ca-file string
    	CA certificate file, required for Mutual TLS (default "~/certs/root_ca.crt")
  -cert-file string
    	Server TLS certificate file (default "~/certs/srv.crt")
  -colors string
    	Comma separated list of output colors [black,red,green,yellow,blue,magenta,cyan,light-gray,
    	dark-gray,light-red,light-green,light-yellow,light-blue,light-magenta,light-cyan,white]
    	
    	hostname header,hostname content,headers,content (default "light-cyan,light-yellow,cyan,yellow")
  -fields string
    	Comma separated list of fields to output
  -fmt string
    	Output format [json,csv,table,vtable] (default "json")
  -key-file string
    	Server TLS key file (default "~/certs/srv.key")
  -mtls
    	Use Mutual TLS, client and server certificate needs to be signed by the same CA authority to establish trust ...TBD...
  -no-color
    	No color output
  -no-tls
    	No TLS (testing)
  -version
    	Version
  resource
    	Resource to query [system,users,groups,filesystems]
  address
        Address to agent specified as <address[:port]> (default port 17711)

Install Go

First install Go and then configure Go environment.

Mac OS X

brew install go

RedHat/CentOS/Fedora

yum install golang

Ubuntu/Debian

apt-get install golang

Setup Go environment

mkdir -p ~/go/{src,bin}
cat << EOF >>~/.bash_profile
export GOPATH=~/go
export PATH=\$PATH:\$GOPATH/bin
EOF
source ~/.bash_profile

Clone code

mkdir -p $GOPATH/src/github.com/peekaboo-labs
cd $GOPATH/src/github.com/peekaboo-labs
git clone https://github.com/peekaboo-labs/peekaboo

Build and run

Build and start agent.

cd $GOPATH/src/github.com/peekaboo-labs/peekaboo
make deps build
./agent/agent -no-tls

Query agent.

./client/client -no-tls -fmt vtable system localhost
frm https://github.com/peekaboo-labs/peekaboo
----
Expose hardware info using JSON/REST。

Expose hardware info using a REST API written in Go and a Front-End written in AngularJS.

FrontEnd

http://myserver.example.com:5050

BackEnd

Endpoints

/api/docker
/api/docker/containers
/api/docker/images
/api/network
/api/network/interfaces
/api/network/routes
/api/storage/disks
/api/storage/lvm/logvols
/api/storage/lvm/physvols
/api/storage/lvm/volgrps
/api/storage/mounts
/api/system
/api/system/cpu
/api/system/ipmi
/api/system/memory
/api/system/os
/api/system/pcicards
/api/system/rpms
/api/system/sysctls
/api/system/kernel/config
/api/system/kernel/modules

Methods

GET

curl -i -X GET http://<host>:<port>/api/system?envelope=true

PURGE

Purge cache i.e. next get request will refresh the cache.

curl -i -X PURGE http://<host>:<port>/api/system?envelope=true

Options

envelope

Include an envelope with error, cache and status information.

?envelope=true

Example:

{
  "cache": {
    "lastUpdated": "...",
    "timeoutSec": 0,
    "fromCache": false
  },
  "data": {
  },
  "error": [],
  "status": 200
}

refresh

Refresh cache.

?refresh=true

indent

Don't indent JSON.

?indent=false

Example:

curl http://myserver.example.com:5050/api/system

Usage

Peekaboo

Usage:
  peekaboo daemon [--debug] [--bind=<addr>] [--static=<dir>]
  peekaboo list
  peekaboo get <hardware-type>
  peekaboo -h | --help
  peekaboo --version

Commands:
  daemon               Start as a daemon serving HTTP requests.
  list                 List hardware names available.
  get                  Return information about hardware.

Arguments:
  hardware-type        Name of hardware to return information about.

Options:
  -h --help            Show this screen.
  --version            Show version.
  -d --debug           Debug.
  -b --bind=<addr>     Bind to address and port. [default: 0.0.0.0:5050]
  -s --static=<dir>    Directory for static content. [default: static]

Setup Go on Linux

sudo yum install -y golang
mkdir ~/go
export GOPATH=~/go
export PATH=$GOPATH/bin:$PATH
go get github.com/constabulary/gb/...

Build and run

gb build
sudo bin/peekaboo daemon -d

Build RPM

Fiest make sure you have Docker configured.

make rpm

Change configuration

systemctl stop peekaboo
vi /etc/sysconfig/peekaboo

Change port to 8080.

Example:

OPTIONS="--bind 0.0.0.0:8080"

Reload SystemD and then restart Peekaboo.

systemctl start peekaboo

Install using Brew on Mac OS X

brew tap mickep76/funk-gnarge
brew install peekaboo
ln -sfv /usr/local/opt/peekaboo/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.peekaboo.plist

Change configuration

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.peekaboo.plist
vi ~/Library/LaunchAgents/homebrew.mxcl.peekaboo.plist

Change port to 8080.

Example:

...
    <string>--bind</string>
    <string>0.0.0.0:8080</string>
..

Restart Peekaboo.

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.peekaboo.plist
frm  https://github.com/imc-trading/peekaboo

No comments:

Post a Comment