GithubHelp home page GithubHelp logo

hostbase-cli's Introduction

Hostbase Command Line Client

The Hostbase CLI features full-text search (using Elasticsearch/Lucene query syntax) and basic CRUD operations, which accept JSON.

Installation

  1. Download the PHAR: https://github.com/shift31/hostbase-cli/raw/master/hostbase.phar

  2. Move it to /usr/local/sbin and rename it to 'hostbase'

  3. Make it executable:

    chmod +x /usr/local/sbin/hostbase

Configuration

Create hostbase-cli.config.php in /etc or your home directory:

<?php

 return array(
     'baseUrl' => 'http://your.hostbase.server'
 );

Configuration for Hostbase Development Server:

<?php

 return array(
     'baseUrl' => 'http://hostbase.192.168.33.10.xip.io'
 );

Usage

Help

Usage:
  [options] command [arguments]

Options:
  --help           -h Display this help message.
  --quiet          -q Do not output any message.
  --verbose        -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
  --version        -V Display this application version.
  --ansi              Force ANSI output.
  --no-ansi           Disable ANSI output.
  --no-interaction -n Do not ask any interactive question.
  --env               The environment the command should run under.

Available commands:
  help          Displays help for a command
  hosts         View and manipulate hosts
  ips           View and manipulate IP addresses
  list          Lists commands
  self-update   Updates the application.
  subnets       View and manipulate subnets

Hosts

hostbase hosts [-j|--json] [-k|--key="..."] [-s|--search] [-l|--limit="..."] [-x|--extendOutput] [-a|--add="..."] [-u|--update="..."] [-d|--delete] fqdn|query

Subnets

hostbase subnets [-j|--json] [-k|--key="..."] [-s|--search] [-l|--limit="..."] [-x|--extendOutput] [-a|--add="..."] [-u|--update="..."] [-d|--delete] subnet|query

IP Addresses

hostbase ips [-j|--json] [-k|--key="..."] [-s|--search] [-l|--limit="..."] [-x|--extendOutput] [-a|--add="..."] [-u|--update="..."] [-d|--delete] ip|query

Add a host

Example adding a host with the mandatory 'fqdn' field and another (arbitrary) field:

  • Raw JSON string:

    hostbase hosts -a '{"fqdn": "hostname.domain.tld", "fooField": "barValue"}' hostname.domain.tld
  • .json file using Bash subshell:

    host.json:

    {
        "fqdn": "hostname.example.com",
        "fooField": "barValue"
    }
    hostbase hosts -a "$(cat host.json)" hostname.example.com

Update a host

Example adding a field (key/value pair):

  • Raw JSON string:

    hostbase hosts -u '{"anotherField": "someValue"}' hostname.domain.tld
  • .json file using Bash subshell:

    host.json:

    {
        "anotherField": "someValue"
    }
    hostbase hosts -u "$(cat host.json)" hostname.example.com

Find a host by FQDN

  • Output Yaml (default):

    hostbase hosts hostname.example.com
  • Output JSON:

    hostbase hosts -j hostname.example.com

Search for a host

Use Elasticsearch/Lucene query syntax

  • Example where 'domain' contains 'example.com'

    hostbase hosts -s 'domain:example.com'
  • Show all host data (output Yaml)

    hostbase hosts -sx 'domain:example.com'
  • Only return values for a specific field/key (using 'operatingsystem' as example)

    This also works when requesting a single host.

    hostbase hosts -s 'domain:example.com' -k operatingsystem
  • List all hosts

    hostbase hosts -s ""

Delete a host

hostbase hosts -d hostname.example.com

Other entities

The 'subnets' and 'ips' commands work the same way as 'hosts'

Laravel Envoy

Using Laravel Envoy, you can easily run tasks on multiple servers (in serial or parallel). Here's an example Envoy.blade.php that retrieves an array of hosts from the output of hostbase and runs ls -la on each server, one at a time:

<?php
$servers = [];
exec('hostbase hosts -s "env:prod AND role:www"', $servers);

$credentials = [];

foreach ($servers as $server) {
  $credentials[$server] = 'root@' . $server;
}
?>

@servers($credentials)

@task('foo', ['on' => $servers])
ls -la
@endtask

hostbase-cli's People

Contributors

bgetsug avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.