Created
January 18, 2018 16:58
-
-
Save trevorstarick/d6cfa07cedd0c16810696e4773cd2c99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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