Fixes.
This commit is contained in:
		
							parent
							
								
									84e96a860c
								
							
						
					
					
						commit
						2d8160212e
					
				| 
						 | 
					@ -2,12 +2,12 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[projects]]
 | 
					[[projects]]
 | 
				
			||||||
  digest = "1:9543804b8019077cb769bc3b15bfb0640fc732f8b061df323a973171b979d02f"
 | 
					  digest = "1:dbd1c953926f2aca29aeb24f13af5875a3b31f09ed7093cb18a5409d4b9fc9f1"
 | 
				
			||||||
  name = "github.com/golift/unifi"
 | 
					  name = "github.com/golift/unifi"
 | 
				
			||||||
  packages = ["."]
 | 
					  packages = ["."]
 | 
				
			||||||
  pruneopts = "UT"
 | 
					  pruneopts = "UT"
 | 
				
			||||||
  revision = "1779d2c07abd748d0d23868356ef517ac2e00e7e"
 | 
					  revision = "034a62e1cb6ef13e724cfab9b8f87dbb130d493c"
 | 
				
			||||||
  version = "v1.0.1"
 | 
					  version = "v2.0.0"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[projects]]
 | 
					[[projects]]
 | 
				
			||||||
  branch = "master"
 | 
					  branch = "master"
 | 
				
			||||||
| 
						 | 
					@ -19,7 +19,7 @@
 | 
				
			||||||
    "v2",
 | 
					    "v2",
 | 
				
			||||||
  ]
 | 
					  ]
 | 
				
			||||||
  pruneopts = "UT"
 | 
					  pruneopts = "UT"
 | 
				
			||||||
  revision = "16c852ea613fa2d42fcdccc9a8b0802a8bdc6140"
 | 
					  revision = "8ff2fc3824fcb533795f9a2f233275f0bb18d6c5"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[projects]]
 | 
					[[projects]]
 | 
				
			||||||
  digest = "1:b56c589214f01a5601e0821387db484617392d0042f26234bf2da853a2f498a1"
 | 
					  digest = "1:b56c589214f01a5601e0821387db484617392d0042f26234bf2da853a2f498a1"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,33 +7,30 @@ var Version = "v1.0.0"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	// App defaults in case they're missing from the config.
 | 
						// App defaults in case they're missing from the config.
 | 
				
			||||||
	defaultConfFile  = "/usr/local/etc/unifi-poller/up.conf"
 | 
						defaultConfFile = "/usr/local/etc/unifi-poller/up.conf"
 | 
				
			||||||
	defaultInterval  = 30 * time.Second
 | 
						defaultInterval = 30 * time.Second
 | 
				
			||||||
	defaultInfxDb    = "unifi"
 | 
						defaultInfxDb   = "unifi"
 | 
				
			||||||
	defaultInfxUser  = "unifi"
 | 
						defaultInfxUser = "unifi"
 | 
				
			||||||
	defaultInfxPass  = "unifi"
 | 
						defaultInfxPass = "unifi"
 | 
				
			||||||
	defaultInfxURL   = "http://127.0.0.1:8086"
 | 
						defaultInfxURL  = "http://127.0.0.1:8086"
 | 
				
			||||||
	defaultUnifUser  = "influx"
 | 
						defaultUnifUser = "influx"
 | 
				
			||||||
	defaultUnifURL   = "https://127.0.0.1:8443"
 | 
						defaultUnifURL  = "https://127.0.0.1:8443"
 | 
				
			||||||
	defaultVerifySSL = false
 | 
					 | 
				
			||||||
	defaultDebug     = false
 | 
					 | 
				
			||||||
	defaultQuiet     = false
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Config represents the data needed to poll a controller and report to influxdb.
 | 
					// Config represents the data needed to poll a controller and report to influxdb.
 | 
				
			||||||
type Config struct {
 | 
					type Config struct {
 | 
				
			||||||
	Interval   Dur      `json:"interval" toml:"interval" xml:"interval" yaml:"interval"`
 | 
						Interval   Dur      `json:"interval,_omitempty" toml:"interval,_omitempty" xml:"interval" yaml:"interval"`
 | 
				
			||||||
	Debug      bool     `json:"debug" toml:"debug" xml:"debug" yaml:"debug"`
 | 
						Debug      bool     `json:"debug" toml:"debug" xml:"debug" yaml:"debug"`
 | 
				
			||||||
	Quiet      bool     `json:"quiet" toml:"quiet" xml:"quiet" yaml:"quiet"`
 | 
						Quiet      bool     `json:"quiet" toml:"quiet" xml:"quiet" yaml:"quiet"`
 | 
				
			||||||
	VerifySSL  bool     `json:"verify_ssl" toml:"verify_ssl" xml:"verify_ssl" yaml:"verify_ssl"`
 | 
						VerifySSL  bool     `json:"verify_ssl" toml:"verify_ssl" xml:"verify_ssl" yaml:"verify_ssl"`
 | 
				
			||||||
	InfluxURL  string   `json:"influx_url" toml:"influx_url" xml:"influx_url" yaml:"influx_url"`
 | 
						InfluxURL  string   `json:"influx_url,_omitempty" toml:"influx_url,_omitempty" xml:"influx_url" yaml:"influx_url"`
 | 
				
			||||||
	InfluxUser string   `json:"influx_user" toml:"influx_user" xml:"influx_user" yaml:"influx_user"`
 | 
						InfluxUser string   `json:"influx_user,_omitempty" toml:"influx_user,_omitempty" xml:"influx_user" yaml:"influx_user"`
 | 
				
			||||||
	InfluxPass string   `json:"influx_pass" toml:"influx_pass" xml:"influx_pass" yaml:"influx_pass"`
 | 
						InfluxPass string   `json:"influx_pass,_omitempty" toml:"influx_pass,_omitempty" xml:"influx_pass" yaml:"influx_pass"`
 | 
				
			||||||
	InfluxDB   string   `json:"influx_db" toml:"influx_db" xml:"influx_db" yaml:"influx_db"`
 | 
						InfluxDB   string   `json:"influx_db,_omitempty" toml:"influx_db,_omitempty" xml:"influx_db" yaml:"influx_db"`
 | 
				
			||||||
	UnifiUser  string   `json:"unifi_user" toml:"unifi_user" xml:"unifi_user" yaml:"unifi_user"`
 | 
						UnifiUser  string   `json:"unifi_user,_omitempty" toml:"unifi_user,_omitempty" xml:"unifi_user" yaml:"unifi_user"`
 | 
				
			||||||
	UnifiPass  string   `json:"unifi_pass" toml:"unifi_pass" xml:"unifi_pass" yaml:"unifi_pass"`
 | 
						UnifiPass  string   `json:"unifi_pass,_omitempty" toml:"unifi_pass,_omitempty" xml:"unifi_pass" yaml:"unifi_pass"`
 | 
				
			||||||
	UnifiBase  string   `json:"unifi_url" toml:"unifi_url" xml:"unifi_url" yaml:"unifi_url"`
 | 
						UnifiBase  string   `json:"unifi_url,_omitempty" toml:"unifi_url,_omitempty" xml:"unifi_url" yaml:"unifi_url"`
 | 
				
			||||||
	Sites      []string `json:"sites" toml:"sites" xml:"sites" yaml:"sites"`
 | 
						Sites      []string `json:"sites,_omitempty" toml:"sites,_omitempty" xml:"sites" yaml:"sites"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Dur is used to UnmarshalTOML into a time.Duration value.
 | 
					// Dur is used to UnmarshalTOML into a time.Duration value.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,7 +28,7 @@ func main() {
 | 
				
			||||||
		log.Fatalf("Config Error '%v': %v", configFile, err)
 | 
							log.Fatalf("Config Error '%v': %v", configFile, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// Create an authenticated session to the Unifi Controller.
 | 
						// Create an authenticated session to the Unifi Controller.
 | 
				
			||||||
	controller, err := unifi.GetController(config.UnifiUser, config.UnifiPass, config.UnifiBase, config.VerifySSL)
 | 
						controller, err := unifi.NewUnifi(config.UnifiUser, config.UnifiPass, config.UnifiBase, config.VerifySSL)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Fatalln("Unifi Controller Error:", err)
 | 
							log.Fatalln("Unifi Controller Error:", err)
 | 
				
			||||||
	} else if !config.Quiet {
 | 
						} else if !config.Quiet {
 | 
				
			||||||
| 
						 | 
					@ -53,7 +53,7 @@ func main() {
 | 
				
			||||||
		controller.DebugLog = nil
 | 
							controller.DebugLog = nil
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		log.Println("Logging Unifi Metrics to InfluXDB @", config.InfluxURL, "as user", config.InfluxUser)
 | 
							log.Println("Logging Unifi Metrics to InfluXDB @", config.InfluxURL, "as user", config.InfluxUser)
 | 
				
			||||||
		log.Println("Polling Unifi Controller, interval:", config.Interval.value)
 | 
							log.Printf("Polling Unifi Controller (sites %v), interval: %v", config.Sites, config.Interval.value)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	config.PollUnifiController(controller, infdb)
 | 
						config.PollUnifiController(controller, infdb)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -83,9 +83,6 @@ func GetConfig(configFile string) (Config, error) {
 | 
				
			||||||
		UnifiUser:  defaultUnifUser,
 | 
							UnifiUser:  defaultUnifUser,
 | 
				
			||||||
		UnifiPass:  os.Getenv("UNIFI_PASSWORD"),
 | 
							UnifiPass:  os.Getenv("UNIFI_PASSWORD"),
 | 
				
			||||||
		UnifiBase:  defaultUnifURL,
 | 
							UnifiBase:  defaultUnifURL,
 | 
				
			||||||
		VerifySSL:  defaultVerifySSL,
 | 
					 | 
				
			||||||
		Debug:      defaultDebug,
 | 
					 | 
				
			||||||
		Quiet:      defaultQuiet,
 | 
					 | 
				
			||||||
		Interval:   Dur{value: defaultInterval},
 | 
							Interval:   Dur{value: defaultInterval},
 | 
				
			||||||
		Sites:      []string{"default"},
 | 
							Sites:      []string{"default"},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,7 +3,7 @@
 | 
				
			||||||
    "list": [
 | 
					    "list": [
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
        "builtIn": 1,
 | 
					        "builtIn": 1,
 | 
				
			||||||
        "datasource": "-- Grafana --",
 | 
					        "datasource": "Unifi",
 | 
				
			||||||
        "enable": true,
 | 
					        "enable": true,
 | 
				
			||||||
        "hide": true,
 | 
					        "hide": true,
 | 
				
			||||||
        "iconColor": "rgba(0, 211, 255, 1)",
 | 
					        "iconColor": "rgba(0, 211, 255, 1)",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -57,7 +57,7 @@
 | 
				
			||||||
    "list": [
 | 
					    "list": [
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
        "builtIn": 1,
 | 
					        "builtIn": 1,
 | 
				
			||||||
        "datasource": "-- Grafana --",
 | 
					        "datasource": "${DS_UNIFI}",
 | 
				
			||||||
        "enable": true,
 | 
					        "enable": true,
 | 
				
			||||||
        "hide": true,
 | 
					        "hide": true,
 | 
				
			||||||
        "iconColor": "rgba(0, 211, 255, 1)",
 | 
					        "iconColor": "rgba(0, 211, 255, 1)",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -57,7 +57,7 @@
 | 
				
			||||||
    "list": [
 | 
					    "list": [
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
        "builtIn": 1,
 | 
					        "builtIn": 1,
 | 
				
			||||||
        "datasource": "-- Grafana --",
 | 
					        "datasource": "${DS_UNIFI}",
 | 
				
			||||||
        "enable": true,
 | 
					        "enable": true,
 | 
				
			||||||
        "hide": true,
 | 
					        "hide": true,
 | 
				
			||||||
        "iconColor": "rgba(0, 211, 255, 1)",
 | 
					        "iconColor": "rgba(0, 211, 255, 1)",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue