Exemplo n.º 1
0
func main() {

	if len(os.Args) < 2 {
		fmt.Printf("%s -h for help\n", os.Args[0])
		os.Exit(1)
	}

	var host = goopt.String([]string{"-H", "--host"}, "127.0.0.1", "The remote host running NRPE-Server")
	var port = goopt.Int([]string{"-p", "--port"}, 5666, "The remote port on which the NRPE-server listens")
	var transport = goopt.Int([]string{"-t", "--transport"}, 0, "Transport type: 0 - clear, 1 - ssl, 2 -ssh")
	var command = goopt.String([]string{"-c", "--command"}, "version",
		"The check command defined in the nrpe.cfg file you would like to trigger")

	goopt.Parse(nil)
	service := fmt.Sprintf("%s:%d", *host, *port)
	conn := prepareConnection(service, *transport)
	pkt_to_send := common.PrepareToSend(*command, common.QUERY_PACKET)
	err := common.SendPacket(conn, pkt_to_send)
	common.CheckError(err)
	response_from_command, _ := common.ReceivePacket(conn)
	fmt.Println(string(response_from_command.CommandBuffer[:]))
	os.Exit(int(response_from_command.ResultCode))
}
Exemplo n.º 2
0
// main handles parsing command line arguments and spawning instances of
// findImages()
func main() {
	rand.Seed(time.Now().UTC().UnixNano())

	var interval = goopt.Int([]string{"-i", "--interval"}, 2000,
		"Milliseconds between requests per connection")
	var connections = goopt.Int([]string{"-c", "--connections"}, 4,
		"Number of simultanious connections")
	var directory = goopt.String([]string{"-d", "--directory"}, "images",
		"Directory to save images to")

	goopt.Description = func() string {
		return "Download random images from imgur"
	}
	goopt.Version = "0.0.1"
	goopt.Summary = "Random imgur downloader"
	goopt.Parse(nil)

	// Create requested number of connections.
	for threadNum := 1; threadNum < *connections; threadNum++ {
		go findImages(*interval, *directory, threadNum)
	}
	findImages(*interval, *directory, 0)
}
Exemplo n.º 3
0
func main() {
	hostEnv := os.Getenv("HOST")
	portEnv := os.Getenv("PORT")

	// default to environment variable values (changes the help string :( )
	if hostEnv == "" {
		hostEnv = "*"
	}

	p := 8080
	if portEnv != "" {
		p, _ = strconv.Atoi(portEnv)
	}

	goopt.Usage = usage

	// server mode options
	host := goopt.String([]string{"-h", "--host"}, hostEnv, "host ip address to bind to")
	port := goopt.Int([]string{"-p", "--port"}, p, "port to listen on")

	// cli mode
	vendor := goopt.String([]string{"-v", "--vendor"}, "", "vendor for cli generation")
	status := goopt.String([]string{"-s", "--status"}, "", "status for cli generation")
	color := goopt.String([]string{"-c", "--color", "--colour"}, "", "color for cli generation")
	goopt.Parse(nil)

	args := goopt.Args

	// if any of the cli args are given, or positional args remain, assume cli
	// mode.
	if len(args) > 0 || *vendor != "" || *status != "" || *color != "" {
		cliMode(*vendor, *status, *color, args)
		return
	}
	// normalize for http serving
	if *host == "*" {
		*host = ""
	}

	http.HandleFunc("/v1/", buckle)
	http.HandleFunc("/favicon.png", favicon)
	http.HandleFunc("/", index)

	log.Println("Listening on port", *port)
	http.ListenAndServe(*host+":"+strconv.Itoa(*port), nil)
}
Exemplo n.º 4
0
func init() {
	goopt.Description = func() string {
		return "conchk v" + goopt.Version
	}
	goopt.Author = "Bruce Fitzsimons <*****@*****.**>"
	goopt.Version = "0.3"
	goopt.Summary = "conchk is an IP connectivity test tool designed to validate that all configured IP connectivity actually works\n " +
		"It reads a list of tests and executes them, in a parallel manner, based on the contents of each line" +
		"conchk supports tcp and udp based tests (IPv4 and IPv6), at this time.\n\n" +
		"==Notes==\n" +
		"* The incuded Excel sheet is a useful way to create and maintain the tests\n" +
		"* testing a range of supports is supported. In this case the rules for a successful test are somewhat different\n" +
		"** If one of the ports gets a successful connect, and the rest are refused (connection refused) as nothing is listening\n" +
		"\tthen this is considered to be a successful test of the range. This is the most common scenario in our experience;\n" +
		"\tthe firewalls and routing are demonstrably working, and at least one destination service is ok. If you need all ports to work\n" +
		"\tthen consider using individual tests\n" +
		"* If all tests for this host pass, then conchk will exit(0). Otherwise it will exit(1)\n" +
		"* conchk will use the current hostname, or the commandline parameter, to find the tests approprate to execute - matches on field 3.\n" +
		"\tThis means all the tests for a system, or project can be placed in one file\n" +
		"* The .csv output option will write a file much like the input file, but with two additional columns and without any comments\n" +
		"\t This file can be fed back into conchk without error.\n\n" +
		"See http://bwooce.github.io/conchk/ for more information.\n\n(c)2013 Bruce Fitzsimons.\n\n"

	Hostname, _ := os.Hostname()

	params.Debug = goopt.Flag([]string{"-d", "--debug"}, []string{}, "additional debugging output", "")
	params.TestsFile = goopt.String([]string{"-T", "--tests"}, "./tests.conchk", "test file to load")
	params.OutputFile = goopt.String([]string{"-O", "--outputcsv"}, "", "name of results .csv file to write to. A pre-existing file will be overwritten.")
	params.MyHost = goopt.String([]string{"-H", "--host"}, Hostname, "Hostname to use for config lookup")
	params.MaxStreams = goopt.Int([]string{"--maxstreams"}, 8, "Maximum simultaneous checks")
	params.Timeout = goopt.String([]string{"--timeout"}, "5s", "TCP connectivity timeout, UDP delay for ICMP responses")

	semStreams = make(semaphore, *params.MaxStreams)
	runtime.GOMAXPROCS(runtime.NumCPU())

}
Exemplo n.º 5
0
package main

import (
	"fmt"
	goopt "github.com/droundy/goopt"
	"github.com/xaviershay/erg"
	"os"
	"strconv"
)

var port = goopt.Int([]string{"-p", "--port"}, 8080, "Port to connect to. Can also be set with RANGE_PORT environment variable.")
var host = goopt.String([]string{"-h", "--host"}, "localhost", "Host to connect to. Can also be set with RANGE_HOST environment variable.")
var ssl = goopt.Flag([]string{"-s", "--ssl"}, []string{"--no-ssl"},
	"Don't use SSL", "Use SSL. Can also be set with RANGE_SSL environment variable.")
var expand = goopt.Flag([]string{"-e", "--expand"}, []string{"--no-expand"},
	"Do not compress results", "Compress results (default)")

func main() {
	if envHost := os.Getenv("RANGE_HOST"); len(envHost) > 0 {
		*host = envHost
	}

	if envSsl := os.Getenv("RANGE_SSL"); len(envSsl) > 0 {
		*ssl = true
	}

	if envPort := os.Getenv("RANGE_PORT"); len(envPort) > 0 {
		x, err := strconv.Atoi(envPort)
		if err == nil {
			*port = x
		} else {
Exemplo n.º 6
0
		line, isPrefix, err = reader.ReadLine()
	}
	if err != nil && err != io.EOF {
		panic(err)
	}
	return result
}

var host = goopt.String([]string{"-h", "--host"},
	"localhost",
	"the host on which the MongoDB server or the ZeroMQ queue is running")
var port = goopt.String([]string{"-p", "--port"},
	"27017",
	"the port on which the MongoDB server or the ZermMQ queue is running")
var duration = goopt.Int([]string{"-d", "--duration"},
	60,
	"the duration of the test in seconds")
var sourceIdFile = goopt.String([]string{"-s", "--sids"},
	"source_ids.txt",
	"the name of the file that contains the list of UUIDs for sources")
var resourceIdFile = goopt.String([]string{"-r", "--rids"},
	"resource_ids.txt",
	"the name of the file that contains the list of UUIDs for resources")
var metricFile = goopt.String([]string{"-c", "--metrics"},
	"metrics.txt",
	"the name of the file that contains the list of metric names")
var maxMetrics = goopt.Int([]string{"-x", "--maxmetrics"},
	5000,
	"the maximum number of metric names that will be used. if the number exceeds the number of names in the metric file the max in the file will be used")
var target = goopt.Alternatives(
	[]string{"-t", "--target"},
Exemplo n.º 7
0
package main

import (
	"fmt"
	"github.com/droundy/goopt"
	"github.com/droundy/gui"
	"github.com/droundy/gui/web"
	"io/ioutil"
	"strconv"
	"strings"
	"έντομο"
)

var port = goopt.Int([]string{"--port"}, 8080, "port on which to serve")

var bug = έντομο.Type("bug")
var todo = έντομο.Type("todo")

func main() {
	err := web.Serve(*port, Page)
	if err != nil {
		panic("ListenAndServe: " + err.String())
	}
}

func Header(page string, p chan<- string) gui.Widget {
	list := gui.Button("Bug list")
	newbug := gui.Button("Report new bug")
	about := gui.Button("About")
	go func() {
		for {
Exemplo n.º 8
0
// Package ftp implements a FTP client as described in RFC 959.
package main

import (
	"fmt"
	goopt "github.com/droundy/goopt"
	ftp "github.com/jlaffaye/ftp"
)

var server_ip = goopt.String([]string{"-h"}, "0.0.0.0", "FTP服务器IP地址")
var server_port = goopt.Int([]string{"-p"}, 21, "FTP服务器端口")
var username = goopt.String([]string{"-u"}, "anonymous", "登陆用户名")
var password = goopt.String([]string{"-k"}, "anonymous", "登陆用户密码")

var dir = goopt.String([]string{"-d"}, "null", "所要查询的目录")
var file = goopt.String([]string{"-f"}, "null", "所要查询的文件名")

func main() {

	goopt.Description = func() string {
		return "Example program for using the goopt flag library."
	}
	goopt.Version = "1.0"
	goopt.Summary = "checker.exe -h 127.0.0.1 -u user -p 123qwe -d /dir -f file1"
	goopt.Parse(nil)

	fmt.Printf("FTP agrs info server_ip[%v]]\n", *server_ip)
	fmt.Printf("FTP agrs info server_port[%v]\n", *server_port)
	fmt.Printf("FTP agrs info username[%v]\n", *username)
	fmt.Printf("FTP agrs info password[%v]\n", *password)
	fmt.Printf("FTP agrs info dir[%v]\n", *dir)
Exemplo n.º 9
0
Arquivo: zmqc.go Projeto: jhawk28/zmqc
	"bufio"
	"fmt"
	flag "github.com/droundy/goopt"
	zmq "github.com/pebbe/zmq4"
	"os"
)

var null = flag.Flag([]string{"-0"}, []string{}, "Separate messages on input/output should be ", "")

var mode = flag.Flag([]string{"-c", "--connect"},
	[]string{"-b", "--bind"},
	"Connect to the specified address(es).",
	"Bind to the specified address(es).")

var number = flag.Int([]string{"-n"}, -1, "Receive/send only NUM messages. By default, zmqc "+
	"lives forever in 'read' mode, or until the end of input "+
	"in 'write' mode.")

var socket_type = flag.Alternatives([]string{"-s"},
	[]string{"PUSH", "PULL", "PUB", "SUB", "REQ", "REP", "PAIR"},
	"Which type of socket to create. Must be one of 'PUSH', 'PULL', "+
		"'PUB', 'SUB', 'REQ', 'REP' or 'PAIR'. See `man zmq_socket` for an "+
		"explanation of the different types. 'DEALER' and 'ROUTER' sockets are "+
		"currently unsupported.")

var subscriptions = flag.Strings([]string{"--subscribe"}, "", "Subscribes to data matching")

func init() {
	flag.Version = "1.0"
	flag.Summary = "zmqc is a small but powerful command-line interface to " +
		"ZeroMQ. It allows you to create a socket of a given type, bind or " +
Exemplo n.º 10
0
package main

import (
	"bytes"
	"log"
	"net"
	"os/exec"
	"regexp"
	"strings"
	"time"

	"github.com/droundy/goopt"
)

var connect = goopt.String([]string{"-s", "--server"}, "127.0.0.1", "Server to connect to (and listen if listening)")
var port = goopt.Int([]string{"-p", "--port"}, 2222, "Port to connect to (and listen to if listening)")

var listen = goopt.Flag([]string{"-l", "--listen"}, []string{}, "Create a listening TFO socket", "")

func main() {

	goopt.Parse(nil)

	// IPv4 only for no real reason, could be v6 by adjusting the sizes
	// here and where it's used
	var serverAddr [4]byte

	IP := net.ParseIP(*connect)
	if IP == nil {
		log.Fatal("Unable to process IP: ", *connect)
	}
Exemplo n.º 11
0
	"os"
	"strings"

	"github.com/droundy/goopt"
	"github.com/ortutay/decloud/conf"
	"github.com/ortutay/decloud/cred"
	"github.com/ortutay/decloud/msg"
	"github.com/ortutay/decloud/node"
	"github.com/ortutay/decloud/services/calc"
	"github.com/ortutay/decloud/services/payment"
	"github.com/ortutay/decloud/services/store"
	"github.com/ortutay/decloud/util"
)

// General flags
var fPort = goopt.Int([]string{"-p", "--port"}, 9443, "")
var fAppDir = goopt.String([]string{"--app-dir"}, "~/.decloud", "")

// var fTestNet = goopt.Flag([]string{"-t", "--test-net"}, []string{"--main-net"}, "Use testnet", "Use mainnet")
var fMaxBalance = goopt.String([]string{"--max-balance"}, ".1BTC", "")

// Cross-service flags
var fMinFee = goopt.String([]string{"--min-fee"}, "calc.calc=.01BTC", "") // TODO(ortutay) unused? remove?
var fMinCoins = goopt.String([]string{"--min-coins"}, "calc.calc=.1BTC", "")
var fMaxWork = goopt.String([]string{"--max-work"}, "calc.calc={\"bytes\": 1000, \"queries\": 100}", "")

// Store service flags
var fStoreDir = goopt.String([]string{"--store:dir"}, "~/.decloud-store", "")
var fStoreMaxSpace = goopt.String([]string{"--store:max-space"}, "1GB", "")
var fStoreGbPricePerMo = goopt.String([]string{"--store:gb-price-per-mo"}, ".001BTC", "")
Exemplo n.º 12
0
var amVerbose = goopt.Flag([]string{"--verbose"}, []string{},
	"output verbosely", "")
var amHappy = goopt.Flag([]string{"-h", "--happy"}, []string{"-u", "--unhappy", "--sad"}, "be happy", "be unhappy")

var foo = goopt.String([]string{"--name"}, "anonymous", "pick your name")
var bar = goopt.String([]string{"-b"}, "BOO!", "pick your scary sound")
var baz = goopt.String([]string{"-o"}, "", "test whether a silent default works")
var speed = goopt.Alternatives([]string{"--speed", "--velocity"},
	[]string{"slow", "medium", "fast"},
	"set the speed")

var words = goopt.Strings([]string{"--word", "--saying", "-w", "-s"}, "word",
	"specify a word to speak")

var width = goopt.Int([]string{"-l", "--length"}, 1, "number of ?s")

func main() {
	goopt.Summary = "silly test program"
	goopt.Parse(nil)
	if *amVerbose {
		fmt.Println("I am verbose.")
	}
	if *amHappy {
		fmt.Println("I am happy")
	} else {
		fmt.Println("I am unhappy")
	}
	fmt.Println("Your name is", *foo)
	fmt.Println(*bar, "... Did I scare you?")
	fmt.Println("I am going so very", *speed, "!!!")
Exemplo n.º 13
0
var amVerbose = goopt.Flag([]string{"-v", "--verbose"}, []string{"--quiet"},
	"output verbosely", "be quiet, instead")

// This is just a logging function that uses the verbosity flags to
// decide whether or not to log anything.
func log(x ...interface{}) {
	if *amVerbose {
		fmt.Println(x...)
	}
}

var color = goopt.Alternatives([]string{"--color", "--colour"},
	[]string{"default", "red", "green", "blue"},
	"determine the color of the output")

var repetitions = goopt.Int([]string{"-n", "--repeat"}, 1, "number of repetitions")

var username = goopt.String([]string{"-u", "--user"}, "User", "name of user")

var children = goopt.Strings([]string{"--child"}, "name of child", "specify child of user")

func main() {
	goopt.Description = func() string {
		return "Example program for using the goopt flag library."
	}
	goopt.Version = "1.0"
	goopt.Summary = "goopt demonstration program"
	goopt.Parse(nil)
	defer fmt.Print("\033[0m") // defer resetting the terminal to default colors
	switch *color {
	case "default":
Exemplo n.º 14
0
	"fmt"
	goopt "github.com/droundy/goopt"
	"net"
	"net/http"
	"net/url"
	"runtime"
	"sort"
	"strings"
	"time"
)

var Author = "Alexander Solovyov"
var Version = "0.2"
var Summary = "gofigure [OPTS] URL\n"

var reqs = goopt.Int([]string{"-n", "--requests"}, 1,
	"number of requests to make")
var concurrency = goopt.Int([]string{"-c", "--concurrency"}, 1,
	"concurrency level")
var timeout = goopt.Int([]string{"-t", "--timeout"}, 1000,
	"timeout of each request in milliseconds")
var cpus = goopt.Int([]string{"-p", "--cpus"}, 0,
	"how many processes to run (0 - default)")

type someError struct {
	what string
	str  string
}

func (e *someError) Error() string {
	return fmt.Sprintf(e.what, e.str)
}
Exemplo n.º 15
0
package main

import (
	"fmt"
	"os"
	"strconv"

	goopt "github.com/droundy/goopt"
	_ "github.com/go-sql-driver/mysql"
)

var port = goopt.String([]string{"-p", "--port"}, "80", "Port to bind server too")

var galeraHost = goopt.String([]string{"-H", "--host"}, "localhost", "Host to check galera status of")
var galeraPort = goopt.Int([]string{"--mysql_port"}, 3306, "Specify a port to connect to")
var mysqlUser = os.Getenv("MYSQL_USERNAME")
var mysqlPassword = os.Getenv("MYSQL_PASSWORD")

func init() {
	//Parse options
	goopt.Parse(nil)

	// Setup goopts
	goopt.Description = func() string {
		return "Galera http Check"
	}
	goopt.Version = "0.9.2"
	goopt.Summary = "galera_http_check [-H] [-p]"

}
Exemplo n.º 16
0
	"github.com/ortutay/decloud/msg"
	"github.com/ortutay/decloud/node"
	"github.com/ortutay/decloud/rep"
	"github.com/ortutay/decloud/services/calc"
	"github.com/ortutay/decloud/services/payment"
	"github.com/ortutay/decloud/util"

	"github.com/andrew-d/go-termutil"
)

// General flags
var fAddr = goopt.String([]string{"-a", "--addr"}, "", "Remote host address")
var fAppDir = goopt.String([]string{"--app-dir"}, "~/.decloud", "")
var fCoinsLower = goopt.String([]string{"--coins-lower"}, "0btc", "")
var fCoinsUpper = goopt.String([]string{"--coins-upper"}, "10btc", "")
var fVerbosity = goopt.Int([]string{"-v", "--verbosity"}, 0, "")

// var fTestNet = goopt.Flag([]string{"-t", "--test-net"}, []string{"--main-net"}, "Use testnet", "Use mainnet")

// Cross-service flags
var fDefer = goopt.String([]string{"--defer"}, "", "Promise deferred payment")

// Store service flags
var fStoreFile = goopt.String([]string{"--store.file"}, "", "File to store")
var fStoreFor = goopt.String([]string{"--store.for"}, "1h", "How long to store")
var fStoreGbPricePerMo = goopt.String([]string{"--store.gb-price-per-mo"}, ".001BTC", "")

func main() {
	goopt.Parse(nil)
	util.SetAppDir(*fAppDir)