Esempio n. 1
0
func makeProber(testname string, c *testConfig,
	logger *log.Logger) libprober.RegisterProber {
	switch c.Testtype {
	case "dns":
		hostname := c.Specs.Hostname
		return dnsprober.New(testname, hostname)
	case "ldap":
		sssd := c.Specs.SssdConfig
		ch := fsutil.WatchFile(sssd, logger)
		file := <-ch
		fsutil.WatchFileStop()
		return ldapprober.Makeldapprober(testname, file, c.Probefreq)
	case "pid":
		pidpath := c.Specs.Pathname
		if pidpath == "" {
			return nil
		}
		return pidprober.Makepidprober(testname, pidpath)
	case "testprog":
		testprogpath := c.Specs.Pathname
		if testprogpath == "" {
			return nil
		}
		return testprogprober.Maketestprogprober(testname, testprogpath)
	case "url":
		urlpath := c.Specs.Urlpath
		urlport := c.Specs.Urlport
		return urlprober.Makeurlprober(testname, urlpath, urlport)
	default:
		logger.Printf("Test type %s not supported", c.Testtype)
		return nil
	}
}
Esempio n. 2
0
func (m *Manager) registerFileForPath(pathname string, sourceFile string) {
	readCloserChannel := fsutil.WatchFile(sourceFile, m.logger)
	fgen := &fileGenerator{
		objectServer: m.objectServer,
		logger:       m.logger}
	fgen.notifierChannel = m.registerHashGeneratorForPath(pathname, fgen)
	go fgen.handleReaders(readCloserChannel)

}
Esempio n. 3
0
func main() {
	flag.Usage = printUsage
	flag.Parse()
	tricorder.RegisterFlags()
	circularBuffer := logbuf.New()
	logger := log.New(circularBuffer, "", log.LstdFlags)
	// We have to have inputs.
	if *sourcesFile == "" {
		printUsage()
		os.Exit(2)
	}
	handleSignals(logger)
	var generators []generator
	readerChannel := fsutil.WatchFile(*sourcesFile, logger)
	file, err := os.Open(*sourcesFile)
	if err != nil {
		showErrorAndDie(err)
	}
	(<-readerChannel).Close()
	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		fields := strings.Fields(scanner.Text())
		if len(fields) == 0 || len(fields[0]) == 0 || fields[0][0] == '#' {
			continue
		}
		gen, err := getSource(fields)
		if err != nil {
			showErrorAndDie(err)
		}
		generators = append(generators, gen)
	}
	if err := scanner.Err(); err != nil {
		showErrorAndDie(err)
	}
	file.Close()
	httpSrv, err := startHttpServer(*portNum)
	if err != nil {
		showErrorAndDie(err)
	}
	httpSrv.AddHtmlWriter(circularBuffer)
	updateFunc := startRpcd(logger)
	go runDaemon(generators, *mdbFile, *hostnameRegex, *datacentre,
		*fetchInterval, updateFunc, logger, *debug)
	<-readerChannel
	fsutil.WatchFileStop()
	if err := syscall.Exec(os.Args[0], os.Args, os.Environ()); err != nil {
		logger.Printf("Unable to Exec:%s: %s\n", os.Args[0], err)
	}
}
Esempio n. 4
0
func main() {
	flag.Usage = printUsage
	flag.Parse()
	tricorder.RegisterFlags()
	if os.Geteuid() == 0 {
		fmt.Fprintln(os.Stderr, "Do not run the filegen server as root")
		os.Exit(1)
	}
	circularBuffer := logbuf.New()
	logger := log.New(circularBuffer, "", log.LstdFlags)
	if err := setupserver.SetupTls(); err != nil {
		logger.Println(err)
		circularBuffer.Flush()
		if !*permitInsecureMode {
			os.Exit(1)
		}
	}
	manager := filegen.New(logger)
	if *configFile != "" {
		if err := util.LoadConfiguration(manager, *configFile); err != nil {
			fmt.Fprintln(os.Stderr, err)
			os.Exit(1)
		}
		ch := fsutil.WatchFile(*configFile, nil)
		(<-ch).Close() // Drain the first event.
		go func() {
			<-ch
			err := syscall.Exec(os.Args[0], os.Args, os.Environ())
			if err != nil {
				logger.Printf("Unable to Exec:%s: %s\n", os.Args[0], err)
			}
		}()
	}
	httpd.AddHtmlWriter(manager)
	httpd.AddHtmlWriter(circularBuffer)
	for _, pathname := range flag.Args() {
		if err := registerSourceDirectory(manager, pathname, "/"); err != nil {
			fmt.Fprintln(os.Stderr, err)
			os.Exit(1)
		}
	}
	if err := httpd.StartServer(*portNum, manager, false); err != nil {
		fmt.Fprintf(os.Stderr, "Unable to create http server: %s\n", err)
		os.Exit(1)
	}
}
Esempio n. 5
0
func fileWatchDaemon(mdbFileName string, mdbChannel chan<- *mdb.Mdb,
	logger *log.Logger) {
	var lastMdb *mdb.Mdb
	for readCloser := range fsutil.WatchFile(mdbFileName, logger) {
		mdb := loadFile(readCloser, mdbFileName, logger)
		readCloser.Close()
		if mdb == nil {
			continue
		}
		compareStartTime := time.Now()
		if lastMdb == nil || !reflect.DeepEqual(lastMdb, mdb) {
			if lastMdb != nil {
				mdbCompareTimeDistribution.Add(time.Since(compareStartTime))
			}
			mdbChannel <- mdb
			lastMdb = mdb
		}
	}
}
Esempio n. 6
0
func (m *Manager) registerTemplateFileForPath(pathname string,
	templateFile string, watchForUpdates bool) error {
	tgen := &templateGenerator{
		objectServer: m.objectServer,
		logger:       m.logger}
	tgen.notifierChannel = m.registerHashGeneratorForPath(pathname, tgen)
	if watchForUpdates {
		readCloserChannel := fsutil.WatchFile(templateFile, m.logger)
		go tgen.handleReadClosers(readCloserChannel)
	} else {
		file, err := os.Open(templateFile)
		if err != nil {
			return err
		}
		if err := tgen.handleReadCloser(file); err != nil {
			return err
		}
	}
	return nil
}