func parse_args() { sflag.Parse(&opt) if opt.Kvplist_ == "" { fmt.Println("monalert: Error in named arguments. See monalert --help") os.Exit(1) } }
func main() { sflag.Parse(&opt) var err error = nil lg, err = genutil.SetupLogger(fmt.Sprintf("%s/%s", opt.Logdir, time.Now().Format(opt.Logfile)), " Alertbase ") if err != nil { log.Println("Error setting up the log file err =", err) return } manageDB() }
func main() { upSince = time.Now() sflag.Parse(&opt) if ports[opt.Env] == "" { fmt.Println("Invalid --Env passed, use one of prod, dev, be") return } readConfig() getCurrOps() go authServer() go alertMailer() registerDataRequestHandlers() http.HandleFunc("/", rootHandler) http.HandleFunc("/api/data", dataRequestHandler) http.HandleFunc("/api/authenticate", authHandler) http.HandleFunc("/api/logout", logoutHandler) http.ListenAndServe(":"+ports[opt.Env], nil) }
func main() { sflag.Parse(&opt) genutil.CheckFileIsReadableAndNonzeroOrDie(opt.Inbase + "/" + opt.Infile) fi, _ := os.Lstat(opt.Inbase + "/" + opt.Infile) modtime := fi.ModTime() outfiles := make([]string, 0) fmt.Println("doing file=", opt.Infile) buf := "" opt.Tempbase = strings.TrimRight(opt.Tempbase, "/ ") opt.Inbase = strings.TrimRight(opt.Inbase, "/ ") opt.Outbase = strings.TrimRight(opt.Outbase, "/ ") dir := opt.Tempbase numrex, err := regexp.Compile("[12][0-9][0-9][0-9][01][0-9][0-3][0-9]") // regexp.MustCompile("\d\d\d\d\d\d\d\d") if err != nil { panic("could not compile date regexp") } infile := opt.Inbase + "/" + opt.Infile inlen := len(infile) if genutil.IsZipFilename(infile) { yyyymmdd2 := genutil.GetYyyymmddFromFilenameYymmddFromEndWithSuffixLen(infile, len(".zip"), "19010101") // grab the YYMMDD from filenames of form foo_YYMMDD.zip if yyyymmdd2 == "19010101" { fmt.Println("skipping unknown zip filename=", infile) return } //tmpdir := genutil.MakeDirOrDie(opt.Tempbase, "TEMP") tmpdir, tmperr := ioutil.TempDir(opt.Tempbase, "vendor1") if tmperr != nil { panic("Cannot create temp dir by ioutil.TempDir, err=" + tmperr.Error()) } buf = genutil.BashExecOrDie(false, "/usr/bin/unzip -u -d "+tmpdir+" "+infile, dir) for _, ff := range genutil.FileList(tmpdir) { fflen := len(ff) yyyymmdd := ff[fflen-8:] if (fflen < 9) || !numrex.MatchString(ff[fflen-8:]) { fmt.Println("substituting non-yyyymmdd fname=", ff, " infile=", infile) yyyymmdd = yyyymmdd2 } ffile := tmpdir + "/" + ff genutil.EnsureDirOrDie(opt.Outbase, yyyymmdd) buf = genutil.BashExecOrDie(false, "/usr/bin/gzip "+ffile, dir) // fmt.Println(buf) buf = genutil.BashExecOrDie(false, "/bin/mv -f "+ffile+".gz "+opt.Outbase+"/"+yyyymmdd, dir) // fmt.Println(buf) os.Chtimes(opt.Outbase+"/"+yyyymmdd+"/"+ff+".gz", modtime, modtime) outfiles = append(outfiles, yyyymmdd+"/"+ff+".gz") } buf = genutil.BashExecOrDie(false, "/bin/rmdir "+tmpdir, dir) // fmt.Println(buf) if false { fmt.Println(buf) } } else if (inlen > 9) && numrex.MatchString(infile[inlen-8:]) { // some files are not zipfiles, but end in a date yyyymmdd := infile[inlen-8:] fmt.Println("nonzip file=", infile, " yyyymmdd=", yyyymmdd) outfile := opt.Outbase + "/" + yyyymmdd + "/" + opt.Infile outfiles = append(outfiles, yyyymmdd+"/"+opt.Infile+".gz") if true { genutil.EnsureDirOrDie(opt.Outbase, yyyymmdd) buf = genutil.BashExecOrDie(false, "/bin/cp -f "+infile+" "+outfile, dir) // fmt.Println(buf) buf = genutil.BashExecOrDie(false, "/usr/bin/gzip -f "+outfile, dir) // fmt.Println(buf) } else { buf = genutil.BashExecOrDie(false, "/usr/bin/gzip -f "+infile, dir) // fmt.Println(buf) genutil.EnsureDirOrDie(opt.Outbase, yyyymmdd) buf = genutil.BashExecOrDie(false, "/bin/mv -f "+infile+".gz "+opt.Outbase+"/"+yyyymmdd, dir) // fmt.Println(buf) } os.Chtimes(outfile+".gz", modtime, modtime) } else { fmt.Println("nonzip file=", infile, "with no yyyymmdd pattern, so doing nothing!") } ccfg := qcfg.NewCfgMem(opt.Metafile) ccfg.EditEntry("splitExample", "file", "outdir", opt.Outbase) ccfg.EditEntry("splitExample", "file", "outfiles", strings.Join(outfiles, ",")) ccfg.CfgWrite(opt.Metafile) }
func main() { sflag.Parse(&opt) usr, err := user.Current() if err != nil { fmt.Println("failed to get uid, exiting.....") return } hostname, err1 := os.Hostname() if err1 != nil { fmt.Println("failed to get hostname, exiting.....") return } if opt.To == "" && opt.Cc == "" && opt.Bcc == "" { usage() return } bodyStr := "" uuid1, _ := exec.Command("uuidgen").Output() uuid := strings.TrimSpace(string(uuid1)) mpartClose := false //true -> multipart message (i.e) msg, attachment bodyStr += "Subject:" + opt.Subject + "\n" if opt.To != "" { bodyStr += "To:" + opt.To + "\n" } if opt.Cc != "" { bodyStr += "Cc:" + opt.Cc + "\n" } if opt.Bcc != "" { bodyStr += "Bcc:" + opt.Bcc + "\n" } if opt.Contents != "/dev/null" || opt.Attachment != "/dev/null" { bodyStr += "Content-Type: multipart/mixed; boundary=\"" + uuid + "\"\nMIME-Version: 1.0\n" } if opt.Contents != "/dev/null" { bodyStr += "\n--" + uuid + "\nContent-Type: text/plain\nContent-Disposition: inline\n\n" mpartClose = true cStr, err := ioutil.ReadFile(opt.Contents) if err != nil { panic("Unable to read contents file: " + err.Error()) } bodyStr += string(cStr) } if opt.Attachment != "/dev/null" { bodyStr += ("\n--" + uuid + "\nContent-Transfer-Encoding: base64\nContent-Type: application/octet-stream; name=" + opt.Attachment + "\nContent-Disposition: attachment; filename=" + opt.Attachment + "\n\n") mpartClose = true cStr, err := ioutil.ReadFile(opt.Attachment) if err != nil { panic("Unable to read attachment file: " + err.Error()) } bodyStr += base64.StdEncoding.EncodeToString(cStr) + "\n" } if mpartClose { bodyStr += "--" + uuid + "--" } cmd := exec.Command("/usr/sbin/sendmail", "-t", "-F", usr.Username+"@"+hostname) cmd.Stdin = strings.NewReader(bodyStr) cmd.Run() }