Beispiel #1
0
func main() {

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

	config_file := goopt.String([]string{"-c", "--config"}, "nrpe.cfg",
		"config file to use")
	//the first option, will be the default, if the -m isnt given
	run_mode := goopt.Alternatives([]string{"-m", "--mode"},
		[]string{"foreground", "daemon", "systemd"}, "operating mode")
	goopt.Parse(nil)

	//implement different run modes..
	fmt.Println(*run_mode)
	config_obj := new(read_config.ReadConfig)
	config_obj.Init(*config_file)
	err := config_obj.ReadConfigFile()
	common.CheckError(err)
	//extract the commands command[cmd_name] = "/bin/foobar"
	config_obj.ReadCommands()
	config_obj.ReadPrivileges()
	//TODO check for errors
	//what we gonna do with the group?
	pwd := drop_privilege.Getpwnam(config_obj.Nrpe_user)
	drop_privilege.DropPrivileges(int(pwd.Uid), int(pwd.Gid))
	//we have to read it from config
	service := ":5666"
	err = setupSocket(4, service, config_obj)
	common.CheckError(err)
}
Beispiel #2
0
	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"},
	[]string{TARGET_MONGO, TARGET_ZMQ, TARGET_TSDB},
	"sets the destination of metrics generated, default is mongo")
var sendMode = goopt.Alternatives(
	[]string{"-m", "--sendmode"},
	[]string{MODE_CONNECT, MODE_BIND},
	"mode used when sending requests over ZeroMQ, default is connect")
var doBatching = goopt.Flag(
	[]string{"--batch"},
	[]string{"--nobatch"},
	"inserts into the database will be batched",
	"inserts into the database will not be batched")
var batchSize = goopt.Int(
	[]string{"-z", "--size", "--batchsize"},
	1000,
	"sets the size of batches when inserting into the database")
Beispiel #3
0
func main() {
	goopt.Summary = "Command line tool to merge minimaps from custom clients in Hafen."
	var sessionFodler = goopt.StringWithLabel([]string{"-d", "--sessions-dir"}, "sessions", "<path>",
		"Specify input folder (instead of default \"sessions\")")
	var mode = goopt.Alternatives([]string{"-m", "--mode"}, []string{"merger", "zoomer", "picture"},
		"Specify mode (instead of default \"merger\")")
	var zoomPath = goopt.StringWithLabel([]string{"-z", "--zoom"}, "", "<session>",
		"Create zoom layers for specific <session> and place them into \"zoommap\" folder")
	var zoomSize = goopt.IntWithLabel([]string{"--zoom-tile-size"}, 100, "<size>",
		"Specify generated tiles size (instead of default 100)")
	var zoomMax = goopt.IntWithLabel([]string{"--zoom-max"}, 5, "<num>",
		"Specify zoom max (instead of default 5)")
	var zoomMin = goopt.IntWithLabel([]string{"--zoom-min"}, 1, "<num>",
		"Specify zoom min (instead of default 1)")
	var picturePath = goopt.StringWithLabel([]string{"-p", "--picture"}, "", "<session>",
		"Create single map picture for specific <session>")
	var outputFodler = goopt.StringWithLabel([]string{"-o", "--output-dir"}, "zoommap", "<path>",
		"Specify output folder for zoom mode (instead of default \"zoommap\")")
	var trimSessions = goopt.IntWithLabel([]string{"-t", "--trim"}, -1, "<count>",
		"Remove sessions with tiles < <count> from result (good for removing cave sessions)")
	var removeNonStandard = goopt.Flag([]string{"-c", "--clean-non-standard"}, []string{},
		"Remove all non-standard maps (size != 100x100)", "")
	var hashCode = goopt.Alternatives([]string{"--hash-method"}, []string{"simple", "border"},
		"Specify hash method (instead of default \"simple\")")

	// Parse CMD
	goopt.Parse(nil)

	// Force change mode for backward compatibility
	if *picturePath != "" && *mode == "merger" {
		*mode = "picture"
	}
	if *zoomPath != "" && *mode == "merger" {
		*mode = "zoomer"
	}

	SESSION_FOLDER = *sessionFodler

	var hashMethod HashMethod
	switch *hashCode {
	case "simple":
		hashMethod = HashMethod{CodeName: *hashCode, Func: generateSimpleHash}
		break
	case "border":
		hashMethod = HashMethod{CodeName: *hashCode, Func: generateBorderHash}
		break
	default:
		panic("Unrecognized hash method!") // this should never happen!
	}

	workingDirectory, _ := filepath.Abs(SESSION_FOLDER)

	if *zoomSize%100 != 0 {
		fmt.Println("Tile size must be in multiples of 100")
		return
	}
	var composeCount = int(*zoomSize / 100)

	// Generate zoom levels for specific session
	if *mode == "zoomer" {
		generateTiles(workingDirectory, *zoomPath, *outputFodler, composeCount, hashMethod, *zoomMin, *zoomMax)
		return
	}

	// Generate single picture for specific session
	if *mode == "picture" {
		generatePicture(workingDirectory, *picturePath)
		return
	}

	// Otherwise, let's make cross-merge
	files, _ := ioutil.ReadDir(workingDirectory)
	if len(files) < 2 {
		fmt.Println("No folders found")
		return
	}

	if *removeNonStandard == true {
		// Remove all sessions with tile size != 100x100
		for j := 0; j < len(files); j++ {
			tiles, _ := ioutil.ReadDir(filepath.Join(workingDirectory, files[j].Name()))
			for i := 0; i < len(tiles); i++ {
				if strings.Contains(tiles[i].Name(), "tile_") {
					sx, sy := getImageDimension(filepath.Join(workingDirectory, files[j].Name(), tiles[i].Name()))
					if sx != 100 || sy != 100 {
						fmt.Printf("Old session removed: %s\n", files[j].Name())
						os.RemoveAll(filepath.Join(workingDirectory, files[j].Name()))
					}
					break
				}
			}
		}
	}

	files, _ = ioutil.ReadDir(workingDirectory)
	if len(files) < 2 {
		fmt.Println("No folders found")
		return
	}
	for j := 0; j < len(files); j++ {
		info, err := os.Stat(filepath.Join(workingDirectory, files[j].Name()))
		if err != nil {
			continue
		}
		if info.IsDir() == false {
			continue
		}

		coreFolder := files[j]
		for i := 1; i < len(files); i++ {
			if i == j {
				continue
			}
			dirInfo, err := os.Stat(filepath.Join(workingDirectory, files[i].Name()))
			if err != nil {
				continue
			}
			if dirInfo.IsDir() == false {
				continue
			}

			res := mergeFolders(filepath.Join(workingDirectory, files[i].Name()), filepath.Join(workingDirectory, coreFolder.Name()), hashMethod)
			if res == true {
				fmt.Printf("Merged (%s, %s)\n", coreFolder.Name(), files[i].Name())
			} else {
				fmt.Printf("Sessions are not mergeable (%s, %s)\n", coreFolder.Name(), files[i].Name())
			}
		}
	}
	files, _ = ioutil.ReadDir(workingDirectory)
	var sessionsJS string = "var sessionsJS = ["
	for j := 0; j < len(files); j++ {
		tiles, _ := ioutil.ReadDir(filepath.Join(workingDirectory, files[j].Name()))
		if *trimSessions > 0 {
			if len(tiles) < *trimSessions {
				err := os.RemoveAll(filepath.Join(workingDirectory, files[j].Name()))
				if err != nil {
					fmt.Printf("Cannot trim session %s: %s\n", files[j].Name(), err.Error())
					continue
				} else {
					fmt.Printf("Trimmed session %s\n", files[j].Name())
					continue
				}
			}
		}
		sessionsJS += "\"" + SESSION_FOLDER + "/" + files[j].Name() + "\", "
	}
	sessionsJS += "];"
	ioutil.WriteFile("session.js", []byte(sessionsJS), 0777)
}
Beispiel #4
0
)

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 " +
		"connect it to multiple addresses, set options on it, and receive or send " +
		"messages over it using standard I/O, in the shell or in scripts."
	flag.Author = "Joshua Foster"
}

func main() {
Beispiel #5
0
//target:entomonitor
package main

import (
	"bufio"
	"fmt"
	"github.com/droundy/goopt"
	"os"
	"έντομο"
)

var action = goopt.Alternatives([]string{"-A", "--action"},
	[]string{"help", "new-issue", "comment"}, "select the action to be performed")
var message = goopt.String([]string{"-m", "--message"}, "", "short message")
var bugid = goopt.String([]string{"-b", "--bug"}, "", "bug ID")

func dieOn(err os.Error) {
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}

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

func main() {
	goopt.Parse(func() []string { return nil })
	pname, err := έντομο.ProjectName()
	dieOn(err)
	fmt.Println("Project name is", pname)
	if *action == "help" {
Beispiel #6
0
import (
	"fmt"
	goopt "github.com/droundy/goopt"
	"strings"
)

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")
Beispiel #7
0
// The Flag function creates a boolean flag, possibly with a negating
// alternative.  Note that you can specify either long or short flags
// naturally in the same list.
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)