Пример #1
0
func hueControl(bridge *hue.Bridge, c chan string) {
	syslog.Info("Launch plex status")
	time.Sleep(1000 * time.Millisecond)
	var previous = "stopped"
	for {
		select {
		case <-r:
			syslog.Info("Exit from plex status")
			return
		case <-time.After(5000 * time.Millisecond):
			switch <-c {
			case "stopped", "paused":
				if previous == "cinema" {
					cinefadeSwitch(bridge, "restore")
					previous = "stopped"
				}
			case "playing":
				if previous == "stopped" {
					cinefadeSwitch(bridge, "cinema")
					previous = "cinema"
				}
			default:
			}
		}
	}
}
Пример #2
0
func main() {
	syslog.Openlog("cvesync", syslog.LOG_PID, syslog.LOG_DAEMON)
	syslog.Info("Cvesync started")

	config = util.Load_Config("/opt/cvesync/etc/settings.json")
	blist = blacklist.Load_Blacklist(config.BlackList)
	cve_feed := nvd.Get_CVE_feed(config.FeedURL, config.CAKeyFile)
	cwes := nvd.Get_CWEs(config.CWEfile)

	ts := tracker.Jira{}
	//ts := tracker.RT{}
	sync(cve_feed, cwes, &ts)

	syslog.Info("Cvesync ended")
}
Пример #3
0
func main() {

	syslog.Openlog("cinefade", syslog.LOG_PID, syslog.LOG_USER)

	var action string
	flag.StringVar(&action, "action", "on", "lights on/off")
	flag.Parse()

	bridge := cinefade.GetBridge(false)
	cinefade.MapRoutes(bridge)

	// make a http server using the goweb.DefaultHttpHandler()
	s := &http.Server{
		Addr:           Address,
		Handler:        goweb.DefaultHttpHandler(),
		ReadTimeout:    10 * time.Second,
		WriteTimeout:   10 * time.Second,
		MaxHeaderBytes: 1 << 20,
	}

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	listener, listenErr := net.Listen("tcp", Address)
	syslog.Info("Server cinefade started")
	syslog.Infof("visit: %s", Address)

	if listenErr != nil {
		syslog.Critf("Could not listen: %s", listenErr)
		os.Exit(1)
	}

	go func() {
		for _ = range c {
			// sig is a ^C, handle it
			// stop the HTTP server
			syslog.Info("Stopping the cinefade server...")
			listener.Close()

			syslog.Info("Tearing down...")
			os.Exit(0)
		}
	}()

	syslog.Critf("Error in Serve: %s", s.Serve(listener))
	os.Exit(1)
}
Пример #4
0
func Info(msg string) {
	switch {
	case *logType == "stderr":
		glog.Infoln(msg)
	case *logType == "syslog":
		syslog.Info(msg)
	}
}
Пример #5
0
func poll(client *http.Client, c chan string) {
	syslog.Info("Launch plex poller")
	conf := config.NewConfig(EtcDir + "/cinefade.conf")
	err := conf.Read()
	if err != nil {
		syslog.Critf("cannot read config: %v", err)
	}
	plexUrl := conf.Get("", "plexUrl")

	for {
		select {
		case <-r:
			syslog.Info("Exit from plex poller")
			r <- true
			return
		case <-time.After(5000 * time.Millisecond):
			req, _ := http.NewRequest("GET", plexUrl, nil)
			resp, err := client.Do(req)
			if err != nil {
				syslog.Warningf("can't access plex %v", err)
				c <- "unknown"
			} else {
				defer resp.Body.Close()

				body, err := ioutil.ReadAll(resp.Body)
				var m MediaContainer
				xml.Unmarshal(body, &m)
				if err != nil {
					syslog.Critf("error: %v", err)
				}
				switch m.Video.Player.State {
				case "":
					c <- "stopped"
				case "paused":
					c <- "paused"
				case "playing":
					c <- "playing"
				default:
					c <- "unknown"
				}
			}
		}
	}
}
Пример #6
0
func cinefadeSwitch(bridge *hue.Bridge, action string) {

	c := make(chan string)
	switch action {
	case "on", "off":
		ControlBulbs(bridge, action)
	case "register":
		SaveBulbsState(bridge, "cinema.json")
	case "cinema":
		syslog.Info("Switch bulbs for cinema")
		if IsOneOfBulbsOn(bridge) {
			_, err := os.Stat(VarDir + "/cinema.json")
			if err != nil {
				syslog.Info("You must first use the register to save cinema lightstate")
			}
			SaveBulbsState(bridge, "current.json")
			SetBulbsState(bridge, "cinema.json")
		} else {
			syslog.Info("Bulbs are off, don't expect any change")
		}
	case "restore":
		syslog.Info("Restore bulbs settings")
		if IsOneOfBulbsOn(bridge) {
			_, err := os.Stat(VarDir + "/current.json")
			if err != nil {
				syslog.Info("Can't call restore action without a backup state")
			}
			SetBulbsState(bridge, "current.json")
		} else {
			syslog.Info("Bulbs are off, don't expect any change")
		}
	case "start":
		RunCheckPlexStatus(bridge, c)
	case "stop":
		StopCheckPlexStatus()
	case "exit":
		syslog.Info("Stopping the cinefade server...")
		go cinefadeExit()
	}
}
Пример #7
0
// output writes the data to the log files and releases the buffer.
func (l *loggingT) output(s severity, buf *buffer) {
	l.mu.Lock()
	if l.traceLocation.isSet() {
		_, file, line, ok := runtime.Caller(3) // It's always the same number of frames to the user's call (same as header).
		if ok && l.traceLocation.match(file, line) {
			buf.Write(stacks(false))
		}
	}
	data := buf.Bytes()

	if l.toStderr {
		os.Stderr.Write(data)
	}

	if l.toSyslog {
		switch s {
		case fatalLog:
			syslog.Emerg(string(data))
		case errorLog:
			syslog.Err(string(data))
		case warningLog:
			syslog.Warning(string(data))
		case infoLog:
			syslog.Info(string(data))
		}
	}

	if l.toFile {
		// JTODO: CONVERT TO JUST MIN THRESHOLD, NOT STDERR THRESHOLD
		// if s >= l.stderrThreshold.get() {
		//     os.Stderr.Write(data)
		// }

		if l.file[s] == nil {
			if err := l.createFiles(s); err != nil {
				os.Stderr.Write(data) // Make sure the message appears somewhere.
				l.exit(err)
			}
		}

		switch s {
		case fatalLog:
			l.file[fatalLog].Write(data)
		case errorLog:
			l.file[errorLog].Write(data)
		case warningLog:
			l.file[warningLog].Write(data)
		case infoLog:
			l.file[infoLog].Write(data)
		}
	}

	if s == fatalLog {
		// Make sure we see the trace for the current goroutine on standard error.
		if !l.toStderr {
			os.Stderr.Write(stacks(false))
		}
		// Write the stack trace for all goroutines to the files.
		trace := stacks(true)
		logExitFunc = func(error) {} // If we get a write error, we'll still exit below.
		for log := fatalLog; log >= infoLog; log-- {
			if f := l.file[log]; f != nil { // Can be nil if -logtostderr is set.
				f.Write(trace)
			}
		}
		l.mu.Unlock()
		timeoutFlush(10 * time.Second)
		os.Exit(255) // C++ uses -1, which is silly because it's anded with 255 anyway.
	}
	l.putBuffer(buf)
	l.mu.Unlock()
	if stats := severityStats[s]; stats != nil {
		atomic.AddInt64(&stats.lines, 1)
		atomic.AddInt64(&stats.bytes, int64(len(data)))
	}
}