Skip to content

Instantly share code, notes, and snippets.

@trevorstarick
Created January 18, 2018 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trevorstarick/d6cfa07cedd0c16810696e4773cd2c99 to your computer and use it in GitHub Desktop.
Save trevorstarick/d6cfa07cedd0c16810696e4773cd2c99 to your computer and use it in GitHub Desktop.
package main
import "os"
import "fmt"
import "strings"
import "io/ioutil"
var err error
var blob string
var path = "/etc/munin/munin-conf.d/hosts.conf"
func init() {
var cnf []byte
cnf, err = ioutil.ReadFile(path)
if err != nil {
panic(err)
}
blob = string(cnf)
}
func main() {
if len(os.Args) != 3 {
os.Exit(1)
}
if strings.Index(blob, fmt.Sprintf("[%v]", os.Args[1])) > 0 {
return
}
if strings.Index(blob, fmt.Sprintf("address %v\n", os.Args[2])) > 0 {
return
}
blob += "\n" + fmt.Sprintf("[%v]\n\taddress %v\n", os.Args[1], os.Args[2])
err = ioutil.WriteFile(path, []byte(blob), 777)
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment