Ejemplo n.º 1
0
// Loading the Filebeat index template into ElasticSearch as described in:
// 	 https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-getting-started.html#filebeat-template
func loadFilebeatIndexTemplate(esHost string) error {
	d := deputy.Deputy{
		Errors:    deputy.FromStderr,
		StdoutLog: func(b []byte) { log.Print(string(b)) },
	}
	cmd2Exc := exec.Command("curl", "-XPUT", esHost+"/_template/filebeat?pretty",
		"-d@/etc/filebeat/filebeat.template.json")

	if err := d.Run(cmd2Exc); err != nil {
		return err
	}
	return nil
}
Ejemplo n.º 2
0
func Example() {
	// Make a new deputy that'll return the data written to stderr as the error
	// message, log everything written to stdout to this application's log,  and
	// timeout after 30 seconds.
	d := deputy.Deputy{
		Errors:    deputy.FromStderr,
		StdoutLog: func(b []byte) { log.Print(string(b)) },
		Timeout:   time.Second * 30,
	}
	if err := d.Run(exec.Command("foo")); err != nil {
		log.Print(err)
	}
}
Ejemplo n.º 3
0
// Mounting an S3 bucket under the mountpoint /mnt/s3 via s3fs-fuse.
func mountS3(bucket string) error {
	d := deputy.Deputy{
		Errors:    deputy.FromStderr,
		StdoutLog: func(b []byte) { log.Print(string(b)) },
		Timeout:   time.Second * 10,
	}

	cmd2Exc := exec.Command("s3fs", bucket, "/mnt/s3", "-o", "passwd_file=/root/aws_creds")

	if err := d.Run(cmd2Exc); err != nil {
		return err
	}
	return nil
}
Ejemplo n.º 4
0
// Starting the Filebeat service using the config file /etc/filebeat/filebeat.yml.
func startFilebeatAgent() error {
	d := deputy.Deputy{
		Errors:    deputy.FromStderr,
		StdoutLog: func(b []byte) { log.Print(string(b)) },
	}
	/*
			Filebeat command line options explanations:
				(Reference: https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-command-line.html)
			-e Log to stderr and disable syslog/file output.
			-v Enable verbose output to show INFO-level messages.

		The output of the filebeat agent will be visible in the Docker output due to redirecting STDERR to STDOUT
		in Bash shell command.
	*/
	cmd2Exc := exec.Command("/bin/bash", "-c", "/usr/bin/filebeat -v -e -c /etc/filebeat/filebeat.yml 2>&1")

	if err := d.Run(cmd2Exc); err != nil {
		return err
	}
	return nil
}