Compare commits
	
		
			6 Commits
		
	
	
		
			v0.4.0
			...
			44bf293eab
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 44bf293eab | |||
| f87b35b306 | |||
| eaf2cf211d | |||
| e8fbacfe6d | |||
| 19823ea08f | |||
| 7fc1fc9b56 | 
							
								
								
									
										2
									
								
								TODO.md
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								TODO.md
									
									
									
									
									
								
							@@ -4,6 +4,8 @@
 | 
				
			|||||||
- [ ] Add Grafana dashboard
 | 
					- [ ] Add Grafana dashboard
 | 
				
			||||||
- [ ] Add proxy to upstream support
 | 
					- [ ] Add proxy to upstream support
 | 
				
			||||||
- [ ] Add new spans
 | 
					- [ ] Add new spans
 | 
				
			||||||
 | 
					- [ ] Fix wunderground 401
 | 
				
			||||||
 | 
					- [ ] Perform proxy calls in goroutines
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Done
 | 
					## Done
 | 
				
			||||||
- [x] Configuration for app
 | 
					- [x] Configuration for app
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										4
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								go.mod
									
									
									
									
									
								
							@@ -4,11 +4,13 @@ go 1.23.4
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
	gitea.libretechconsulting.com/rmcguire/go-app v0.3.1
 | 
						gitea.libretechconsulting.com/rmcguire/go-app v0.3.1
 | 
				
			||||||
 | 
						github.com/go-resty/resty/v2 v2.16.3
 | 
				
			||||||
	github.com/gorilla/schema v1.4.1
 | 
						github.com/gorilla/schema v1.4.1
 | 
				
			||||||
	github.com/rs/zerolog v1.33.0
 | 
						github.com/rs/zerolog v1.33.0
 | 
				
			||||||
	go.opentelemetry.io/otel v1.33.0
 | 
						go.opentelemetry.io/otel v1.33.0
 | 
				
			||||||
	go.opentelemetry.io/otel/metric v1.33.0
 | 
						go.opentelemetry.io/otel/metric v1.33.0
 | 
				
			||||||
	golang.org/x/sys v0.29.0
 | 
						golang.org/x/sys v0.29.0
 | 
				
			||||||
 | 
						k8s.io/utils v0.0.0-20241210054802-24370beab758
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
@@ -22,7 +24,7 @@ require (
 | 
				
			|||||||
	github.com/google/uuid v1.6.0 // indirect
 | 
						github.com/google/uuid v1.6.0 // indirect
 | 
				
			||||||
	github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 // indirect
 | 
						github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 // indirect
 | 
				
			||||||
	github.com/klauspost/compress v1.17.11 // indirect
 | 
						github.com/klauspost/compress v1.17.11 // indirect
 | 
				
			||||||
	github.com/mattn/go-colorable v0.1.13 // indirect
 | 
						github.com/mattn/go-colorable v0.1.14 // indirect
 | 
				
			||||||
	github.com/mattn/go-isatty v0.0.20 // indirect
 | 
						github.com/mattn/go-isatty v0.0.20 // indirect
 | 
				
			||||||
	github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
 | 
						github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
 | 
				
			||||||
	github.com/prometheus/client_golang v1.20.5 // indirect
 | 
						github.com/prometheus/client_golang v1.20.5 // indirect
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										21
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								go.sum
									
									
									
									
									
								
							@@ -1,5 +1,3 @@
 | 
				
			|||||||
gitea.libretechconsulting.com/rmcguire/go-app v0.3.0 h1:TSR6oEDBX+83975gmgGgU/cTFgfG999+9N/1h4RAXq0=
 | 
					 | 
				
			||||||
gitea.libretechconsulting.com/rmcguire/go-app v0.3.0/go.mod h1:wHOWh4O4AMDATQ3WEUYjq5a5bnICPBpu5G6BsNxqN38=
 | 
					 | 
				
			||||||
gitea.libretechconsulting.com/rmcguire/go-app v0.3.1 h1:jydcJ+Vv8sk+Le7nTI2+b6E7FfV+ShBJo7YdxmdaCYc=
 | 
					gitea.libretechconsulting.com/rmcguire/go-app v0.3.1 h1:jydcJ+Vv8sk+Le7nTI2+b6E7FfV+ShBJo7YdxmdaCYc=
 | 
				
			||||||
gitea.libretechconsulting.com/rmcguire/go-app v0.3.1/go.mod h1:wHOWh4O4AMDATQ3WEUYjq5a5bnICPBpu5G6BsNxqN38=
 | 
					gitea.libretechconsulting.com/rmcguire/go-app v0.3.1/go.mod h1:wHOWh4O4AMDATQ3WEUYjq5a5bnICPBpu5G6BsNxqN38=
 | 
				
			||||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
 | 
					github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
 | 
				
			||||||
@@ -20,6 +18,8 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
 | 
				
			|||||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
 | 
					github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
 | 
				
			||||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
 | 
					github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
 | 
				
			||||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
 | 
					github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
 | 
				
			||||||
 | 
					github.com/go-resty/resty/v2 v2.16.3 h1:zacNT7lt4b8M/io2Ahj6yPypL7bqx9n1iprfQuodV+E=
 | 
				
			||||||
 | 
					github.com/go-resty/resty/v2 v2.16.3/go.mod h1:hkJtXbA2iKHzJheXYvQ8snQES5ZLGKMwQ07xAwp/fiA=
 | 
				
			||||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
 | 
					github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
 | 
				
			||||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
 | 
					github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
 | 
				
			||||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
 | 
					github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
 | 
				
			||||||
@@ -39,8 +39,9 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
 | 
				
			|||||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
 | 
					github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
 | 
				
			||||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
 | 
					github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
 | 
				
			||||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
 | 
					github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
 | 
				
			||||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
 | 
					 | 
				
			||||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
 | 
					github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
 | 
				
			||||||
 | 
					github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
 | 
				
			||||||
 | 
					github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
 | 
				
			||||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
 | 
					github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
 | 
				
			||||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
 | 
					github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
 | 
				
			||||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
 | 
					github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
 | 
				
			||||||
@@ -91,14 +92,10 @@ go.opentelemetry.io/otel/sdk/metric v1.33.0 h1:Gs5VK9/WUJhNXZgn8MR6ITatvAmKeIuCt
 | 
				
			|||||||
go.opentelemetry.io/otel/sdk/metric v1.33.0/go.mod h1:dL5ykHZmm1B1nVRk9dDjChwDmt81MjVp3gLkQRwKf/Q=
 | 
					go.opentelemetry.io/otel/sdk/metric v1.33.0/go.mod h1:dL5ykHZmm1B1nVRk9dDjChwDmt81MjVp3gLkQRwKf/Q=
 | 
				
			||||||
go.opentelemetry.io/otel/trace v1.33.0 h1:cCJuF7LRjUFso9LPnEAHJDB2pqzp+hbO8eu1qqW2d/s=
 | 
					go.opentelemetry.io/otel/trace v1.33.0 h1:cCJuF7LRjUFso9LPnEAHJDB2pqzp+hbO8eu1qqW2d/s=
 | 
				
			||||||
go.opentelemetry.io/otel/trace v1.33.0/go.mod h1:uIcdVUZMpTAmz0tI1z04GoVSezK37CbGV4fr1f2nBck=
 | 
					go.opentelemetry.io/otel/trace v1.33.0/go.mod h1:uIcdVUZMpTAmz0tI1z04GoVSezK37CbGV4fr1f2nBck=
 | 
				
			||||||
go.opentelemetry.io/proto/otlp v1.4.0 h1:TA9WRvW6zMwP+Ssb6fLoUIuirti1gGbP28GcKG1jgeg=
 | 
					 | 
				
			||||||
go.opentelemetry.io/proto/otlp v1.4.0/go.mod h1:PPBWZIP98o2ElSqI35IHfu7hIhSwvc5N38Jw8pXuGFY=
 | 
					 | 
				
			||||||
go.opentelemetry.io/proto/otlp v1.5.0 h1:xJvq7gMzB31/d406fB8U5CBdyQGw4P399D1aQWU/3i4=
 | 
					go.opentelemetry.io/proto/otlp v1.5.0 h1:xJvq7gMzB31/d406fB8U5CBdyQGw4P399D1aQWU/3i4=
 | 
				
			||||||
go.opentelemetry.io/proto/otlp v1.5.0/go.mod h1:keN8WnHxOy8PG0rQZjJJ5A2ebUoafqWp0eVQ4yIXvJ4=
 | 
					go.opentelemetry.io/proto/otlp v1.5.0/go.mod h1:keN8WnHxOy8PG0rQZjJJ5A2ebUoafqWp0eVQ4yIXvJ4=
 | 
				
			||||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
 | 
					go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
 | 
				
			||||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
 | 
					go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
 | 
				
			||||||
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
 | 
					 | 
				
			||||||
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
 | 
					 | 
				
			||||||
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
 | 
					golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
 | 
				
			||||||
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
 | 
					golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
@@ -108,18 +105,14 @@ golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
 | 
				
			|||||||
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 | 
					golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 | 
				
			||||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
 | 
					golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
 | 
				
			||||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
 | 
					golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
 | 
				
			||||||
google.golang.org/genproto/googleapis/api v0.0.0-20250102185135-69823020774d h1:H8tOf8XM88HvKqLTxe755haY6r1fqqzLbEnfrmLXlSA=
 | 
					golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
 | 
				
			||||||
google.golang.org/genproto/googleapis/api v0.0.0-20250102185135-69823020774d/go.mod h1:2v7Z7gP2ZUOGsaFyxATQSRoBnKygqVq2Cwnvom7QiqY=
 | 
					golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
 | 
				
			||||||
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 h1:GVIKPyP/kLIyVOgOnTwFOrvQaQUzOzGMCxgFUOEmm24=
 | 
					google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 h1:GVIKPyP/kLIyVOgOnTwFOrvQaQUzOzGMCxgFUOEmm24=
 | 
				
			||||||
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422/go.mod h1:b6h1vNKhxaSoEI+5jc3PJUCustfli/mRab7295pY7rw=
 | 
					google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422/go.mod h1:b6h1vNKhxaSoEI+5jc3PJUCustfli/mRab7295pY7rw=
 | 
				
			||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250102185135-69823020774d h1:xJJRGY7TJcvIlpSrN3K6LAWgNFUILlO+OMAqtg9aqnw=
 | 
					 | 
				
			||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250102185135-69823020774d/go.mod h1:3ENsm/5D1mzDyhpzeRi1NR784I0BcofWBoSc5QqqMK4=
 | 
					 | 
				
			||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422 h1:3UsHvIr4Wc2aW4brOaSCmcxh9ksica6fHEr8P1XhkYw=
 | 
					google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422 h1:3UsHvIr4Wc2aW4brOaSCmcxh9ksica6fHEr8P1XhkYw=
 | 
				
			||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422/go.mod h1:3ENsm/5D1mzDyhpzeRi1NR784I0BcofWBoSc5QqqMK4=
 | 
					google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422/go.mod h1:3ENsm/5D1mzDyhpzeRi1NR784I0BcofWBoSc5QqqMK4=
 | 
				
			||||||
google.golang.org/grpc v1.69.2 h1:U3S9QEtbXC0bYNvRtcoklF3xGtLViumSYxWykJS+7AU=
 | 
					google.golang.org/grpc v1.69.2 h1:U3S9QEtbXC0bYNvRtcoklF3xGtLViumSYxWykJS+7AU=
 | 
				
			||||||
google.golang.org/grpc v1.69.2/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
 | 
					google.golang.org/grpc v1.69.2/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
 | 
				
			||||||
google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk=
 | 
					 | 
				
			||||||
google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
 | 
					 | 
				
			||||||
google.golang.org/protobuf v1.36.2 h1:R8FeyR1/eLmkutZOM5CWghmo5itiG9z0ktFlTVLuTmU=
 | 
					google.golang.org/protobuf v1.36.2 h1:R8FeyR1/eLmkutZOM5CWghmo5itiG9z0ktFlTVLuTmU=
 | 
				
			||||||
google.golang.org/protobuf v1.36.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
 | 
					google.golang.org/protobuf v1.36.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
 | 
				
			||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 | 
					gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 | 
				
			||||||
@@ -127,3 +120,5 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
 | 
				
			|||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
 | 
					gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
 | 
				
			||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 | 
					gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 | 
				
			||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
					gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
				
			||||||
 | 
					k8s.io/utils v0.0.0-20241210054802-24370beab758 h1:sdbE21q2nlQtFh65saZY+rRM6x6aJJI8IUa1AmH/qa0=
 | 
				
			||||||
 | 
					k8s.io/utils v0.0.0-20241210054802-24370beab758/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										5
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								main.go
									
									
									
									
									
								
							@@ -10,6 +10,7 @@ import (
 | 
				
			|||||||
	"golang.org/x/sys/unix"
 | 
						"golang.org/x/sys/unix"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/ambient"
 | 
						"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/ambient"
 | 
				
			||||||
 | 
						"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/ambient/config"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const defaultMetricPrefix = "weather"
 | 
					const defaultMetricPrefix = "weather"
 | 
				
			||||||
@@ -19,9 +20,9 @@ func main() {
 | 
				
			|||||||
	defer cncl()
 | 
						defer cncl()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Config type for app, which implements go-app/config.AppConfig
 | 
						// Config type for app, which implements go-app/config.AppConfig
 | 
				
			||||||
	awConfig := &ambient.AmbientLocalExporterConfig{
 | 
						awConfig := &config.AmbientLocalExporterConfig{
 | 
				
			||||||
		MetricPrefix:    defaultMetricPrefix,
 | 
							MetricPrefix:    defaultMetricPrefix,
 | 
				
			||||||
		WeatherStations: make([]ambient.WeatherStation, 0),
 | 
							WeatherStations: make([]config.WeatherStation, 0),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Read config and environment, set up logging, load up
 | 
						// Read config and environment, set up logging, load up
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,12 +7,14 @@ import (
 | 
				
			|||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
 | 
						"sync"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
 | 
						"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
 | 
				
			||||||
	"github.com/rs/zerolog"
 | 
						"github.com/rs/zerolog"
 | 
				
			||||||
	"go.opentelemetry.io/otel/attribute"
 | 
						"go.opentelemetry.io/otel/attribute"
 | 
				
			||||||
	"go.opentelemetry.io/otel/codes"
 | 
						"go.opentelemetry.io/otel/codes"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/ambient/config"
 | 
				
			||||||
	"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/provider"
 | 
						"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/provider"
 | 
				
			||||||
	"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/provider/awn"
 | 
						"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/provider/awn"
 | 
				
			||||||
	"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/provider/wunderground"
 | 
						"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/provider/wunderground"
 | 
				
			||||||
@@ -24,7 +26,7 @@ type AmbientWeather struct {
 | 
				
			|||||||
	// when either "AmbientWeather" or "Wunderground" are selected
 | 
						// when either "AmbientWeather" or "Wunderground" are selected
 | 
				
			||||||
	// in the "Custom" section of the AWNet app, or the web UI
 | 
						// in the "Custom" section of the AWNet app, or the web UI
 | 
				
			||||||
	// of an Ambient WeatherHub
 | 
						// of an Ambient WeatherHub
 | 
				
			||||||
	config      *AmbientLocalExporterConfig
 | 
						config      *config.AmbientLocalExporterConfig
 | 
				
			||||||
	awnProvider provider.AmbientProvider
 | 
						awnProvider provider.AmbientProvider
 | 
				
			||||||
	wuProvider  provider.AmbientProvider
 | 
						wuProvider  provider.AmbientProvider
 | 
				
			||||||
	appCtx      context.Context
 | 
						appCtx      context.Context
 | 
				
			||||||
@@ -32,7 +34,7 @@ type AmbientWeather struct {
 | 
				
			|||||||
	l           *zerolog.Logger
 | 
						l           *zerolog.Logger
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func New(appCtx context.Context, awConfig *AmbientLocalExporterConfig) *AmbientWeather {
 | 
					func New(appCtx context.Context, awConfig *config.AmbientLocalExporterConfig) *AmbientWeather {
 | 
				
			||||||
	return &AmbientWeather{
 | 
						return &AmbientWeather{
 | 
				
			||||||
		config: awConfig,
 | 
							config: awConfig,
 | 
				
			||||||
		appCtx: appCtx,
 | 
							appCtx: appCtx,
 | 
				
			||||||
@@ -114,6 +116,46 @@ func (aw *AmbientWeather) handleProviderRequest(
 | 
				
			|||||||
		Any("update", update).
 | 
							Any("update", update).
 | 
				
			||||||
		Msg("successfully handled update")
 | 
							Msg("successfully handled update")
 | 
				
			||||||
	w.Write([]byte("ok"))
 | 
						w.Write([]byte("ok"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Proxy update to one or both services if configured to do so
 | 
				
			||||||
 | 
						// Uses a weather update to allow awn to publish to wunderground and
 | 
				
			||||||
 | 
						// visa versa.
 | 
				
			||||||
 | 
						if station := update.StationConfig; station != nil {
 | 
				
			||||||
 | 
							// Perform proxy updates in parallel if enabled
 | 
				
			||||||
 | 
							var proxyWg sync.WaitGroup
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if station.ProxyToAWN {
 | 
				
			||||||
 | 
								proxyWg.Add(1)
 | 
				
			||||||
 | 
								go func() {
 | 
				
			||||||
 | 
									defer proxyWg.Done()
 | 
				
			||||||
 | 
									err := aw.awnProvider.ProxyReq(ctx, update)
 | 
				
			||||||
 | 
									if err != nil {
 | 
				
			||||||
 | 
										zerolog.Ctx(aw.appCtx).Err(err).Msg("failed to proxy to ambient weather")
 | 
				
			||||||
 | 
										return
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									zerolog.Ctx(aw.appCtx).Debug().
 | 
				
			||||||
 | 
										Str("station", station.Name).
 | 
				
			||||||
 | 
										Msg("proxied weather update to awn")
 | 
				
			||||||
 | 
								}()
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if station.ProxyToWunderground {
 | 
				
			||||||
 | 
								proxyWg.Add(1)
 | 
				
			||||||
 | 
								go func() {
 | 
				
			||||||
 | 
									defer proxyWg.Done()
 | 
				
			||||||
 | 
									err := aw.wuProvider.ProxyReq(ctx, update)
 | 
				
			||||||
 | 
									if err != nil {
 | 
				
			||||||
 | 
										zerolog.Ctx(aw.appCtx).Err(err).Msg("failed to proxy to ambient weather")
 | 
				
			||||||
 | 
										return
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									zerolog.Ctx(aw.appCtx).Debug().
 | 
				
			||||||
 | 
										Str("station", station.Name).
 | 
				
			||||||
 | 
										Msg("proxied weather update to wunderground")
 | 
				
			||||||
 | 
								}()
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							proxyWg.Wait()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (aw *AmbientWeather) InitMetrics() {
 | 
					func (aw *AmbientWeather) InitMetrics() {
 | 
				
			||||||
@@ -127,13 +169,7 @@ func (aw *AmbientWeather) enrichStation(update *weather.WeatherUpdate) {
 | 
				
			|||||||
	if update != nil && update.StationID != nil && *update.StationID != "" {
 | 
						if update != nil && update.StationID != nil && *update.StationID != "" {
 | 
				
			||||||
		for _, station := range aw.config.WeatherStations {
 | 
							for _, station := range aw.config.WeatherStations {
 | 
				
			||||||
			if *update.StationID == station.AWNPassKey || *update.StationID == station.WundergroundID {
 | 
								if *update.StationID == station.AWNPassKey || *update.StationID == station.WundergroundID {
 | 
				
			||||||
				update.StationInfo = &weather.StationInfo{
 | 
									update.StationConfig = &station
 | 
				
			||||||
					Type:      update.StationType,
 | 
					 | 
				
			||||||
					Equipment: &station.Equipment,
 | 
					 | 
				
			||||||
					Name:      &station.Name,
 | 
					 | 
				
			||||||
					Keep:      station.KeepMetrics,
 | 
					 | 
				
			||||||
					Drop:      station.DropMetrics,
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,9 +1,7 @@
 | 
				
			|||||||
package ambient
 | 
					package config
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
 | 
						"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/weather"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// This configuration includes all config from go-app/config.AppConfig
 | 
					// This configuration includes all config from go-app/config.AppConfig
 | 
				
			||||||
@@ -17,10 +15,9 @@ type WeatherStation struct {
 | 
				
			|||||||
	Name      string `yaml:"name"`      // Human Friendly Name (e.g. Back Yard Weather)
 | 
						Name      string `yaml:"name"`      // Human Friendly Name (e.g. Back Yard Weather)
 | 
				
			||||||
	Equipment string `yaml:"equipment"` // Equipment Type (e.g. WS-5000)
 | 
						Equipment string `yaml:"equipment"` // Equipment Type (e.g. WS-5000)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// One of these is required, based on the type
 | 
						// Required if proxying to awn/wu is enabled
 | 
				
			||||||
	// set in the "Custom" weather service on your
 | 
					 | 
				
			||||||
	// console, weather station, or weather hub
 | 
					 | 
				
			||||||
	WundergroundID       string `yaml:"wundergroundID"`
 | 
						WundergroundID       string `yaml:"wundergroundID"`
 | 
				
			||||||
 | 
						WundergroundPassword string `yaml:"wundergroundPassword"`
 | 
				
			||||||
	AWNPassKey           string `yaml:"awnPassKey"`
 | 
						AWNPassKey           string `yaml:"awnPassKey"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Proxy updates to AWN or Wunderground
 | 
						// Proxy updates to AWN or Wunderground
 | 
				
			||||||
@@ -31,7 +28,9 @@ type WeatherStation struct {
 | 
				
			|||||||
	// will be excluded if present in discardMetrics
 | 
						// will be excluded if present in discardMetrics
 | 
				
			||||||
	//
 | 
						//
 | 
				
			||||||
	// If anything is present in keepMetrics, it is solely applied,
 | 
						// If anything is present in keepMetrics, it is solely applied,
 | 
				
			||||||
	// ignoring discardMetrics
 | 
						// ignoring discardMetrics.
 | 
				
			||||||
	KeepMetrics []weather.WeatherUpdateField `yaml:"keepMetrics"`
 | 
						//
 | 
				
			||||||
	DropMetrics []weather.WeatherUpdateField `yaml:"dropMetrics"`
 | 
						// Check weather.WeatherUpdateField for options
 | 
				
			||||||
 | 
						KeepMetrics []string `yaml:"keepMetrics"`
 | 
				
			||||||
 | 
						DropMetrics []string `yaml:"dropMetrics"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -13,7 +13,18 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type AWNProvider struct{}
 | 
					type AWNProvider struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const providerName = "awn"
 | 
					const (
 | 
				
			||||||
 | 
						providerName = "awn"
 | 
				
			||||||
 | 
						awnURL       = "http://ambientweather.net/data/report"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Battery Sensors
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						BattOutdoorSensor = "OutdoorSensor"
 | 
				
			||||||
 | 
						BattIndoorSensor  = "IndoorSensor"
 | 
				
			||||||
 | 
						BattRainSensor    = "RainSensor"
 | 
				
			||||||
 | 
						BattCO2Sensor     = "CO2Sensor"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (awn *AWNProvider) Name() string {
 | 
					func (awn *AWNProvider) Name() string {
 | 
				
			||||||
	return providerName
 | 
						return providerName
 | 
				
			||||||
@@ -63,19 +74,19 @@ func MapAwnUpdate(awnUpdate *AmbientWeatherUpdate) *weather.WeatherUpdate {
 | 
				
			|||||||
		TotalRainIn:    awnUpdate.TotalRainIn,
 | 
							TotalRainIn:    awnUpdate.TotalRainIn,
 | 
				
			||||||
		Batteries: []weather.BatteryStatus{
 | 
							Batteries: []weather.BatteryStatus{
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				Component: "OutdoorSensor",
 | 
									Component: BattOutdoorSensor,
 | 
				
			||||||
				Status:    awnUpdate.BattOut,
 | 
									Status:    awnUpdate.BattOut,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				Component: "IndoorSensor",
 | 
									Component: BattIndoorSensor,
 | 
				
			||||||
				Status:    awnUpdate.BattIn,
 | 
									Status:    awnUpdate.BattIn,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				Component: "RainSensor",
 | 
									Component: BattRainSensor,
 | 
				
			||||||
				Status:    awnUpdate.BattRain,
 | 
									Status:    awnUpdate.BattRain,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				Component: "CO2Sensor",
 | 
									Component: BattCO2Sensor,
 | 
				
			||||||
				Status:    awnUpdate.BattCO2,
 | 
									Status:    awnUpdate.BattCO2,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										105
									
								
								pkg/provider/awn/proxy.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								pkg/provider/awn/proxy.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,105 @@
 | 
				
			|||||||
 | 
					package awn
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"net/url"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
 | 
				
			||||||
 | 
						"github.com/go-resty/resty/v2"
 | 
				
			||||||
 | 
						"github.com/rs/zerolog/log"
 | 
				
			||||||
 | 
						"go.opentelemetry.io/otel/attribute"
 | 
				
			||||||
 | 
						"go.opentelemetry.io/otel/codes"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/weather"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Attempts to proxy the weather station update to awn
 | 
				
			||||||
 | 
					// SAMPLE:
 | 
				
			||||||
 | 
					// {"PASSKEY":["ABF7E052BC7325A32300ACC89112AA91"],"baromabsin":["28.895"],
 | 
				
			||||||
 | 
					// "baromrelin":["29.876"],"battin":["1"],"battout":["1"],"battrain":["1"],
 | 
				
			||||||
 | 
					// "dailyrainin":["0.000"],"dateutc":["2025-01-11 22:07:57"],"eventrainin":["0.000"],
 | 
				
			||||||
 | 
					// "hourlyrainin":["0.000"],"humidity":["76"],"humidityin":["31"],"maxdailygust":["7.83"],
 | 
				
			||||||
 | 
					// "monthlyrainin":["0.000"],"solarradiation":["14.21"],"stationtype":["WeatherHub_V1.0.1"],
 | 
				
			||||||
 | 
					// "tempf":["29.48"],"tempinf":["66.20"],"totalrainin":["0.000"],"uv":["0"],
 | 
				
			||||||
 | 
					// "weeklyrainin":["0.000"],"winddir":["66"],"winddir_avg10m":["268"],"windgustmph":["2.68"],
 | 
				
			||||||
 | 
					// "windspeedmph":["0.00"],"yearlyrainin":["0.000"]}
 | 
				
			||||||
 | 
					func (awn *AWNProvider) ProxyReq(ctx context.Context, update *weather.WeatherUpdate) error {
 | 
				
			||||||
 | 
						tracer := otel.GetTracer(ctx, "awnProvider", "proxyReq")
 | 
				
			||||||
 | 
						ctx, span := tracer.Start(ctx, "proxyToAWN")
 | 
				
			||||||
 | 
						defer span.End()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if update.StationConfig.AWNPassKey == "" {
 | 
				
			||||||
 | 
							err := errors.New("no PASSKEY set in update")
 | 
				
			||||||
 | 
							span.RecordError(err)
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						params := updateToAWNParams(update)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err := resty.New().R().
 | 
				
			||||||
 | 
							SetContext(ctx).
 | 
				
			||||||
 | 
							SetQueryParamsFromValues(*params).
 | 
				
			||||||
 | 
							Get(awnURL)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							span.RecordError(err)
 | 
				
			||||||
 | 
							span.SetAttributes(
 | 
				
			||||||
 | 
								attribute.String("query", resp.Request.QueryParam.Encode()),
 | 
				
			||||||
 | 
								attribute.String("body", string(resp.Body())),
 | 
				
			||||||
 | 
							)
 | 
				
			||||||
 | 
							span.SetStatus(codes.Error, err.Error())
 | 
				
			||||||
 | 
							log.Err(err).Any("query", resp.Request.PathParams).
 | 
				
			||||||
 | 
								Int("statusCode", resp.StatusCode()).
 | 
				
			||||||
 | 
								Msg("awn proxy failed")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						span.SetAttributes(
 | 
				
			||||||
 | 
							attribute.Int("statusCode", resp.StatusCode()),
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func updateToAWNParams(update *weather.WeatherUpdate) *url.Values {
 | 
				
			||||||
 | 
						params := &url.Values{}
 | 
				
			||||||
 | 
						params.Set("dateutc", time.Now().Format(time.DateTime))
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "PASSKEY", &update.StationConfig.AWNPassKey)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "baromabsin", update.BaromAbsoluteIn)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "baromrelin", update.BaromRelativeIn)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "dailyrainin", update.DailyRainIn)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "weeklyrainin", update.WeeklyRainIn)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "eventrainin", update.EventRainIn)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "hourlyrainin", update.HourlyRainIn)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "monthlyrainin", update.MonthlyRainIn)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "yearlyrainin", update.YearlyRainIn)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "totalrainin", update.TotalRainIn)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "humidity", update.HumidityOudoor)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "humidityin", update.HumidityIndoor)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "solarradiation", update.SolarRadiation)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "uv", update.UV)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "stationtype", update.StationType)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "tempf", update.TempOutdoorF)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "tempinf", update.TempIndoorF)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "winddir", update.WindDir)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "winddir_avg10m", update.WindDirAvg10m)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "windgustmph", update.WindGustMPH)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "windspeedmph", update.WindSpeedMPH)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "maxdailygust", update.MaxDailyGust)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Batteries
 | 
				
			||||||
 | 
						for _, status := range update.Batteries {
 | 
				
			||||||
 | 
							switch status.Component {
 | 
				
			||||||
 | 
							case BattOutdoorSensor:
 | 
				
			||||||
 | 
								weather.SetURLVal(params, "battin", status.Status)
 | 
				
			||||||
 | 
							case BattIndoorSensor:
 | 
				
			||||||
 | 
								weather.SetURLVal(params, "battout", status.Status)
 | 
				
			||||||
 | 
							case BattRainSensor:
 | 
				
			||||||
 | 
								weather.SetURLVal(params, "battrain", status.Status)
 | 
				
			||||||
 | 
							case BattCO2Sensor:
 | 
				
			||||||
 | 
								weather.SetURLVal(params, "batt_co2", status.Status)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return params
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -11,5 +11,6 @@ import (
 | 
				
			|||||||
// Ambient Weather Network HTTP requests to a stable struct
 | 
					// Ambient Weather Network HTTP requests to a stable struct
 | 
				
			||||||
type AmbientProvider interface {
 | 
					type AmbientProvider interface {
 | 
				
			||||||
	ReqToWeather(context.Context, *http.Request) (*weather.WeatherUpdate, error)
 | 
						ReqToWeather(context.Context, *http.Request) (*weather.WeatherUpdate, error)
 | 
				
			||||||
 | 
						ProxyReq(context.Context, *weather.WeatherUpdate) error
 | 
				
			||||||
	Name() string
 | 
						Name() string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,7 +13,10 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type WUProvider struct{}
 | 
					type WUProvider struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const providerName = "weatherunderground"
 | 
					const (
 | 
				
			||||||
 | 
						providerName = "weatherunderground"
 | 
				
			||||||
 | 
						wuURL        = "https://rtupdate.wunderground.com/weatherstation/updateweatherstation.php"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (wu *WUProvider) Name() string {
 | 
					func (wu *WUProvider) Name() string {
 | 
				
			||||||
	return providerName
 | 
						return providerName
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										88
									
								
								pkg/provider/wunderground/proxy.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								pkg/provider/wunderground/proxy.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,88 @@
 | 
				
			|||||||
 | 
					package wunderground
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"net/url"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/go-resty/resty/v2"
 | 
				
			||||||
 | 
						"github.com/rs/zerolog/log"
 | 
				
			||||||
 | 
						"go.opentelemetry.io/otel/attribute"
 | 
				
			||||||
 | 
						"go.opentelemetry.io/otel/codes"
 | 
				
			||||||
 | 
						"k8s.io/utils/ptr"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/weather"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (wu *WUProvider) ProxyReq(ctx context.Context, update *weather.WeatherUpdate) error {
 | 
				
			||||||
 | 
						tracer := otel.GetTracer(ctx, "wuProvider", "proxyReq")
 | 
				
			||||||
 | 
						ctx, span := tracer.Start(ctx, "proxyToWunderground")
 | 
				
			||||||
 | 
						defer span.End()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if update.StationConfig.WundergroundID == "" {
 | 
				
			||||||
 | 
							err := errors.New("no wunderground id set in update")
 | 
				
			||||||
 | 
							span.RecordError(err)
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						} else if update.StationConfig.WundergroundPassword == "" {
 | 
				
			||||||
 | 
							err := errors.New("no wunderground id set in update")
 | 
				
			||||||
 | 
							span.RecordError(err)
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						params := updateToWuParams(update)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err := resty.New().R().
 | 
				
			||||||
 | 
							SetContext(ctx).
 | 
				
			||||||
 | 
							SetQueryParamsFromValues(*params).
 | 
				
			||||||
 | 
							Get(wuURL)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							span.SetStatus(codes.Error, err.Error())
 | 
				
			||||||
 | 
							span.SetAttributes(
 | 
				
			||||||
 | 
								attribute.String("query", resp.Request.QueryParam.Encode()),
 | 
				
			||||||
 | 
								attribute.String("body", string(resp.Body())),
 | 
				
			||||||
 | 
							)
 | 
				
			||||||
 | 
							span.RecordError(err)
 | 
				
			||||||
 | 
							log.Err(err).
 | 
				
			||||||
 | 
								Int("statusCode", resp.StatusCode()).
 | 
				
			||||||
 | 
								Any("query", resp.Request.PathParams).
 | 
				
			||||||
 | 
								Msg("wunderground proxy failed")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						span.SetAttributes(
 | 
				
			||||||
 | 
							attribute.Int("statusCode", resp.StatusCode()),
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func updateToWuParams(u *weather.WeatherUpdate) *url.Values {
 | 
				
			||||||
 | 
						params := &url.Values{}
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "ID", &u.StationConfig.WundergroundID)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "PASSWORD", &u.StationConfig.WundergroundPassword)
 | 
				
			||||||
 | 
						params.Set("action", "updateraw")
 | 
				
			||||||
 | 
						params.Set("dateutc", "now")
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "UV", u.UV)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "baromin", u.BaromRelativeIn)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "dailyrainin", u.DailyRainIn)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "dewptf", u.DewPointF)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "humidity", u.HumidityOudoor)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "indoorhumidity", u.HumidityIndoor)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "indoortempf", u.TempIndoorF)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "lowbatt", ptr.To(0))
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "monthlyrainin", u.MonthlyRainIn)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "rainin", u.HourlyRainIn)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "realtime", ptr.To(1))
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "rtfreq", ptr.To(60))
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "softwaretype", u.StationType)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "solarradiation", u.SolarRadiation)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "tempf", u.TempOutdoorF)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "weeklyrainin", u.WeeklyRainIn)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "windchillf", u.WindChillF)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "winddir", u.WindDir)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "windgustmph", u.WindGustMPH)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "windspeedmph", u.WindSpeedMPH)
 | 
				
			||||||
 | 
						weather.SetURLVal(params, "yearlyrainin", u.YearlyRainIn)
 | 
				
			||||||
 | 
						return params
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,10 +1,16 @@
 | 
				
			|||||||
package weather
 | 
					package weather
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import "math"
 | 
					import (
 | 
				
			||||||
 | 
						"math"
 | 
				
			||||||
 | 
						"net/url"
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/ambient/config"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Attempts to complete missing fields that may not
 | 
					// Attempts to complete missing fields that may not
 | 
				
			||||||
// be set by a specific provider, such as DewPoint and WindChill
 | 
					// be set by a specific provider, such as DewPoint and WindChill
 | 
				
			||||||
func (u *WeatherUpdate) Enrich() {
 | 
					func (u *WeatherUpdate) Enrich(weatherStations ...*config.WeatherStation) {
 | 
				
			||||||
	if u == nil {
 | 
						if u == nil {
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -53,3 +59,31 @@ func CalculateWindChill(tempF float64, windSpeedMPH float64) float64 {
 | 
				
			|||||||
		35.75*math.Pow(windSpeedMPH, 0.16) +
 | 
							35.75*math.Pow(windSpeedMPH, 0.16) +
 | 
				
			||||||
		0.4275*tempF*math.Pow(windSpeedMPH, 0.16)
 | 
							0.4275*tempF*math.Pow(windSpeedMPH, 0.16)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Helper function to set values from fields
 | 
				
			||||||
 | 
					// typically from a WeatherUpdate
 | 
				
			||||||
 | 
					func SetURLVal(vals *url.Values, key string, value any) {
 | 
				
			||||||
 | 
						if value == nil {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						switch v := value.(type) {
 | 
				
			||||||
 | 
						case *float64:
 | 
				
			||||||
 | 
							if v == nil {
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							str := strconv.FormatFloat(*v, 'f', 4, 64)
 | 
				
			||||||
 | 
							vals.Set(key, str)
 | 
				
			||||||
 | 
						case *int:
 | 
				
			||||||
 | 
							if v == nil {
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							str := strconv.FormatInt(int64(*v), 10)
 | 
				
			||||||
 | 
							vals.Set(key, str)
 | 
				
			||||||
 | 
						case *string:
 | 
				
			||||||
 | 
							if v == nil {
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							vals.Set(key, *v)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -119,46 +119,46 @@ func (wm *WeatherMetrics) Update(u *WeatherUpdate) {
 | 
				
			|||||||
		attributes = append(attributes,
 | 
							attributes = append(attributes,
 | 
				
			||||||
			attribute.String("station_type", *u.StationType))
 | 
								attribute.String("station_type", *u.StationType))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if u.StationInfo != nil {
 | 
						if u.StationConfig != nil {
 | 
				
			||||||
		if u.StationInfo.Name != nil {
 | 
							if u.StationConfig.Name != "" {
 | 
				
			||||||
			attributes = append(attributes,
 | 
								attributes = append(attributes,
 | 
				
			||||||
				attribute.String("station_name", *u.StationInfo.Name))
 | 
									attribute.String("station_name", u.StationConfig.Name))
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if u.StationInfo.Equipment != nil {
 | 
							if u.StationConfig.Equipment != "" {
 | 
				
			||||||
			attributes = append(attributes,
 | 
								attributes = append(attributes,
 | 
				
			||||||
				attribute.String("station_equipment", *u.StationInfo.Equipment))
 | 
									attribute.String("station_equipment", u.StationConfig.Equipment))
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Float64Gauge: wm.TempOutdoorF, FloatVal: u.TempOutdoorF, Field: FieldTempOutdoorF, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Float64Gauge: wm.TempOutdoorF, FloatVal: u.TempOutdoorF, Field: FieldTempOutdoorF, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Float64Gauge: wm.TempIndoorF, FloatVal: u.TempIndoorF, Field: FieldTempIndoorF, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Float64Gauge: wm.TempIndoorF, FloatVal: u.TempIndoorF, Field: FieldTempIndoorF, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Int64Gauge: wm.HumidityOudoor, IntVal: u.HumidityOudoor, Field: FieldHumidityOudoor, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Int64Gauge: wm.HumidityOudoor, IntVal: u.HumidityOudoor, Field: FieldHumidityOudoor, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Int64Gauge: wm.HumidityIndoor, IntVal: u.HumidityIndoor, Field: FieldHumidityIndoor, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Int64Gauge: wm.HumidityIndoor, IntVal: u.HumidityIndoor, Field: FieldHumidityIndoor, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Float64Gauge: wm.WindSpeedMPH, FloatVal: u.WindSpeedMPH, Field: FieldWindSpeedMPH, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Float64Gauge: wm.WindSpeedMPH, FloatVal: u.WindSpeedMPH, Field: FieldWindSpeedMPH, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Float64Gauge: wm.WindGustMPH, FloatVal: u.WindGustMPH, Field: FieldWindGustMPH, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Float64Gauge: wm.WindGustMPH, FloatVal: u.WindGustMPH, Field: FieldWindGustMPH, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Float64Gauge: wm.MaxDailyGust, FloatVal: u.MaxDailyGust, Field: FieldMaxDailyGust, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Float64Gauge: wm.MaxDailyGust, FloatVal: u.MaxDailyGust, Field: FieldMaxDailyGust, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Int64Gauge: wm.WindDir, IntVal: u.WindDir, Field: FieldWindDir, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Int64Gauge: wm.WindDir, IntVal: u.WindDir, Field: FieldWindDir, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Int64Gauge: wm.WindDirAvg10m, IntVal: u.WindDirAvg10m, Field: FieldWindDirAvg10m, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Int64Gauge: wm.WindDirAvg10m, IntVal: u.WindDirAvg10m, Field: FieldWindDirAvg10m, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Int64Gauge: wm.UV, IntVal: u.UV, Field: FieldUV, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Int64Gauge: wm.UV, IntVal: u.UV, Field: FieldUV, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Float64Gauge: wm.SolarRadiation, FloatVal: u.SolarRadiation, Field: FieldSolarRadiation, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Float64Gauge: wm.SolarRadiation, FloatVal: u.SolarRadiation, Field: FieldSolarRadiation, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Float64Gauge: wm.HourlyRainIn, FloatVal: u.HourlyRainIn, Field: FieldHourlyRainIn, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Float64Gauge: wm.HourlyRainIn, FloatVal: u.HourlyRainIn, Field: FieldHourlyRainIn, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Float64Gauge: wm.EventRainIn, FloatVal: u.EventRainIn, Field: FieldEventRainIn, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Float64Gauge: wm.EventRainIn, FloatVal: u.EventRainIn, Field: FieldEventRainIn, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Float64Gauge: wm.DailyRainIn, FloatVal: u.DailyRainIn, Field: FieldDailyRainIn, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Float64Gauge: wm.DailyRainIn, FloatVal: u.DailyRainIn, Field: FieldDailyRainIn, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Float64Gauge: wm.WeeklyRainIn, FloatVal: u.WeeklyRainIn, Field: FieldWeeklyRainIn, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Float64Gauge: wm.WeeklyRainIn, FloatVal: u.WeeklyRainIn, Field: FieldWeeklyRainIn, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Float64Gauge: wm.MonthlyRainIn, FloatVal: u.MonthlyRainIn, Field: FieldMonthlyRainIn, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Float64Gauge: wm.MonthlyRainIn, FloatVal: u.MonthlyRainIn, Field: FieldMonthlyRainIn, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Float64Gauge: wm.YearlyRainIn, FloatVal: u.YearlyRainIn, Field: FieldYearlyRainIn, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Float64Gauge: wm.YearlyRainIn, FloatVal: u.YearlyRainIn, Field: FieldYearlyRainIn, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Float64Gauge: wm.TotalRainIn, FloatVal: u.TotalRainIn, Field: FieldTotalRainIn, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Float64Gauge: wm.TotalRainIn, FloatVal: u.TotalRainIn, Field: FieldTotalRainIn, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Float64Gauge: wm.BaromRelativeIn, FloatVal: u.BaromRelativeIn, Field: FieldBaromRelativeIn, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Float64Gauge: wm.BaromRelativeIn, FloatVal: u.BaromRelativeIn, Field: FieldBaromRelativeIn, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Float64Gauge: wm.BaromAbsoluteIn, FloatVal: u.BaromAbsoluteIn, Field: FieldBaromAbsoluteIn, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Float64Gauge: wm.BaromAbsoluteIn, FloatVal: u.BaromAbsoluteIn, Field: FieldBaromAbsoluteIn, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Float64Gauge: wm.DewPointF, FloatVal: u.DewPointF, Field: FieldDewPointF, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Float64Gauge: wm.DewPointF, FloatVal: u.DewPointF, Field: FieldDewPointF, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
	wm.recorder.Record(&RecordOpts{Float64Gauge: wm.WindChillF, FloatVal: u.WindChillF, Field: FieldWindChillF, Attributes: attributes, StationInfo: u.StationInfo})
 | 
						wm.recorder.Record(&RecordOpts{Float64Gauge: wm.WindChillF, FloatVal: u.WindChillF, Field: FieldWindChillF, Attributes: attributes, Station: u.StationConfig})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Batteries
 | 
						// Batteries
 | 
				
			||||||
	for _, battery := range u.Batteries {
 | 
						for _, battery := range u.Batteries {
 | 
				
			||||||
		batAttr := attributes
 | 
							batAttr := attributes
 | 
				
			||||||
		batAttr = append(batAttr, attribute.String("component", battery.Component))
 | 
							batAttr = append(batAttr, attribute.String("component", battery.Component))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		wm.recorder.Record(&RecordOpts{Int64Gauge: wm.BatteryStatus, IntVal: battery.Status, Field: FieldBatteries, Attributes: batAttr, StationInfo: u.StationInfo})
 | 
							wm.recorder.Record(&RecordOpts{Int64Gauge: wm.BatteryStatus, IntVal: battery.Status, Field: FieldBatteries, Attributes: batAttr, Station: u.StationConfig})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wm.UpdatesReceived.Add(wm.appCtx, 1)
 | 
						wm.UpdatesReceived.Add(wm.appCtx, 1)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,6 +7,8 @@ import (
 | 
				
			|||||||
	"github.com/rs/zerolog"
 | 
						"github.com/rs/zerolog"
 | 
				
			||||||
	"go.opentelemetry.io/otel/attribute"
 | 
						"go.opentelemetry.io/otel/attribute"
 | 
				
			||||||
	"go.opentelemetry.io/otel/metric"
 | 
						"go.opentelemetry.io/otel/metric"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/ambient/config"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type MetricRecorder struct {
 | 
					type MetricRecorder struct {
 | 
				
			||||||
@@ -20,15 +22,15 @@ type RecordOpts struct {
 | 
				
			|||||||
	IntVal       *int
 | 
						IntVal       *int
 | 
				
			||||||
	FloatVal     *float64
 | 
						FloatVal     *float64
 | 
				
			||||||
	Attributes   []attribute.KeyValue
 | 
						Attributes   []attribute.KeyValue
 | 
				
			||||||
	Field        WeatherUpdateField
 | 
						Field        string
 | 
				
			||||||
	StationInfo  *StationInfo
 | 
						Station      *config.WeatherStation
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (r *MetricRecorder) Record(opts *RecordOpts) {
 | 
					func (r *MetricRecorder) Record(opts *RecordOpts) {
 | 
				
			||||||
	if opts.StationInfo != nil && !opts.keep() {
 | 
						if opts.Station != nil && !opts.keep() {
 | 
				
			||||||
		r.l.Trace().
 | 
							r.l.Trace().
 | 
				
			||||||
			Str("field", string(opts.Field)).
 | 
								Str("field", string(opts.Field)).
 | 
				
			||||||
			Str("station", *opts.StationInfo.Name).
 | 
								Str("station", opts.Station.Name).
 | 
				
			||||||
			Msg("Metric dropped by station config")
 | 
								Msg("Metric dropped by station config")
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	} else if opts.Int64Gauge == nil && opts.Float64Gauge == nil {
 | 
						} else if opts.Int64Gauge == nil && opts.Float64Gauge == nil {
 | 
				
			||||||
@@ -39,8 +41,8 @@ func (r *MetricRecorder) Record(opts *RecordOpts) {
 | 
				
			|||||||
	if opts.Int64Gauge != nil {
 | 
						if opts.Int64Gauge != nil {
 | 
				
			||||||
		if opts.IntVal == nil {
 | 
							if opts.IntVal == nil {
 | 
				
			||||||
			log := r.l.Trace().Str("field", string(opts.Field))
 | 
								log := r.l.Trace().Str("field", string(opts.Field))
 | 
				
			||||||
			if opts.StationInfo != nil {
 | 
								if opts.Station != nil {
 | 
				
			||||||
				log = log.Str("station", *opts.StationInfo.Name)
 | 
									log = log.Str("station", opts.Station.Name)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			log.Msg("Dropping nil int metric")
 | 
								log.Msg("Dropping nil int metric")
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
@@ -49,8 +51,8 @@ func (r *MetricRecorder) Record(opts *RecordOpts) {
 | 
				
			|||||||
	} else if opts.Float64Gauge != nil {
 | 
						} else if opts.Float64Gauge != nil {
 | 
				
			||||||
		if opts.FloatVal == nil {
 | 
							if opts.FloatVal == nil {
 | 
				
			||||||
			log := r.l.Trace().Str("field", string(opts.Field))
 | 
								log := r.l.Trace().Str("field", string(opts.Field))
 | 
				
			||||||
			if opts.StationInfo != nil {
 | 
								if opts.Station != nil {
 | 
				
			||||||
				log = log.Str("station", *opts.StationInfo.Name)
 | 
									log = log.Str("station", opts.Station.Name)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			log.Msg("Dropping nil float metric")
 | 
								log.Msg("Dropping nil float metric")
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
@@ -61,8 +63,8 @@ func (r *MetricRecorder) Record(opts *RecordOpts) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (o *RecordOpts) keep() bool {
 | 
					func (o *RecordOpts) keep() bool {
 | 
				
			||||||
	// If keep fields are given, only check keep fields
 | 
						// If keep fields are given, only check keep fields
 | 
				
			||||||
	if len(o.StationInfo.Keep) > 0 {
 | 
						if len(o.Station.KeepMetrics) > 0 {
 | 
				
			||||||
		for _, f := range o.StationInfo.Keep {
 | 
							for _, f := range o.Station.KeepMetrics {
 | 
				
			||||||
			if f == o.Field {
 | 
								if f == o.Field {
 | 
				
			||||||
				return true
 | 
									return true
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@@ -70,7 +72,7 @@ func (o *RecordOpts) keep() bool {
 | 
				
			|||||||
		return false
 | 
							return false
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, f := range o.StationInfo.Drop {
 | 
						for _, f := range o.Station.DropMetrics {
 | 
				
			||||||
		if f == o.Field {
 | 
							if f == o.Field {
 | 
				
			||||||
			return false
 | 
								return false
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,13 +2,15 @@ package weather
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/ambient/config"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Stable intermediate struct containing superset of fields
 | 
					// Stable intermediate struct containing superset of fields
 | 
				
			||||||
// between AWN and Wunderground style updates from Ambient devices
 | 
					// between AWN and Wunderground style updates from Ambient devices
 | 
				
			||||||
type WeatherUpdate struct {
 | 
					type WeatherUpdate struct {
 | 
				
			||||||
	DateUTC         *time.Time
 | 
						DateUTC         *time.Time
 | 
				
			||||||
	StationInfo     *StationInfo
 | 
						StationConfig   *config.WeatherStation
 | 
				
			||||||
	StationID       *string
 | 
						StationID       *string
 | 
				
			||||||
	StationType     *string
 | 
						StationType     *string
 | 
				
			||||||
	TempOutdoorF    *float64
 | 
						TempOutdoorF    *float64
 | 
				
			||||||
@@ -36,14 +38,8 @@ type WeatherUpdate struct {
 | 
				
			|||||||
	// if not otherwise set
 | 
						// if not otherwise set
 | 
				
			||||||
	DewPointF  *float64
 | 
						DewPointF  *float64
 | 
				
			||||||
	WindChillF *float64
 | 
						WindChillF *float64
 | 
				
			||||||
}
 | 
						// First URL parameters given to AWN/Wunderground
 | 
				
			||||||
 | 
						// if proxying is enabled
 | 
				
			||||||
type StationInfo struct {
 | 
					 | 
				
			||||||
	Type      *string
 | 
					 | 
				
			||||||
	Equipment *string
 | 
					 | 
				
			||||||
	Name      *string
 | 
					 | 
				
			||||||
	Keep      []WeatherUpdateField
 | 
					 | 
				
			||||||
	Drop      []WeatherUpdateField
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type BatteryStatus struct {
 | 
					type BatteryStatus struct {
 | 
				
			||||||
@@ -51,34 +47,40 @@ type BatteryStatus struct {
 | 
				
			|||||||
	Status    *int
 | 
						Status    *int
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type WeatherUpdateField string
 | 
					// CHORE: Maintain this, used to check against
 | 
				
			||||||
 | 
					// keep and drop lists
 | 
				
			||||||
// NOTE: Annoyance to avoid string constant comparisons
 | 
					// TODO: Use refelct/ast to generate code
 | 
				
			||||||
// CHORE: Maintain this
 | 
					 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	FieldDateUTC         WeatherUpdateField = "DateUTC"
 | 
						FieldDateUTC         = "DateUTC"
 | 
				
			||||||
	FieldStationType     WeatherUpdateField = "StationType"
 | 
						FieldStationType     = "StationType"
 | 
				
			||||||
	FieldTempOutdoorF    WeatherUpdateField = "TempOutdoorF"
 | 
						FieldTempOutdoorF    = "TempOutdoorF"
 | 
				
			||||||
	FieldTempIndoorF     WeatherUpdateField = "TempIndoorF"
 | 
						FieldTempIndoorF     = "TempIndoorF"
 | 
				
			||||||
	FieldHumidityOudoor  WeatherUpdateField = "HumidityOudoor"
 | 
						FieldHumidityOudoor  = "HumidityOudoor"
 | 
				
			||||||
	FieldHumidityIndoor  WeatherUpdateField = "HumidityIndoor"
 | 
						FieldHumidityIndoor  = "HumidityIndoor"
 | 
				
			||||||
	FieldWindSpeedMPH    WeatherUpdateField = "WindSpeedMPH"
 | 
						FieldWindSpeedMPH    = "WindSpeedMPH"
 | 
				
			||||||
	FieldWindGustMPH     WeatherUpdateField = "WindGustMPH"
 | 
						FieldWindGustMPH     = "WindGustMPH"
 | 
				
			||||||
	FieldMaxDailyGust    WeatherUpdateField = "MaxDailyGust"
 | 
						FieldMaxDailyGust    = "MaxDailyGust"
 | 
				
			||||||
	FieldWindDir         WeatherUpdateField = "WindDir"
 | 
						FieldWindDir         = "WindDir"
 | 
				
			||||||
	FieldWindDirAvg10m   WeatherUpdateField = "WindDirAvg10m"
 | 
						FieldWindDirAvg10m   = "WindDirAvg10m"
 | 
				
			||||||
	FieldUV              WeatherUpdateField = "UV"
 | 
						FieldUV              = "UV"
 | 
				
			||||||
	FieldSolarRadiation  WeatherUpdateField = "SolarRadiation"
 | 
						FieldSolarRadiation  = "SolarRadiation"
 | 
				
			||||||
	FieldHourlyRainIn    WeatherUpdateField = "HourlyRainIn"
 | 
						FieldHourlyRainIn    = "HourlyRainIn"
 | 
				
			||||||
	FieldEventRainIn     WeatherUpdateField = "EventRainIn"
 | 
						FieldEventRainIn     = "EventRainIn"
 | 
				
			||||||
	FieldDailyRainIn     WeatherUpdateField = "DailyRainIn"
 | 
						FieldDailyRainIn     = "DailyRainIn"
 | 
				
			||||||
	FieldWeeklyRainIn    WeatherUpdateField = "WeeklyRainIn"
 | 
						FieldWeeklyRainIn    = "WeeklyRainIn"
 | 
				
			||||||
	FieldMonthlyRainIn   WeatherUpdateField = "MonthlyRainIn"
 | 
						FieldMonthlyRainIn   = "MonthlyRainIn"
 | 
				
			||||||
	FieldYearlyRainIn    WeatherUpdateField = "YearlyRainIn"
 | 
						FieldYearlyRainIn    = "YearlyRainIn"
 | 
				
			||||||
	FieldTotalRainIn     WeatherUpdateField = "TotalRainIn"
 | 
						FieldTotalRainIn     = "TotalRainIn"
 | 
				
			||||||
	FieldBatteries       WeatherUpdateField = "Batteries"
 | 
						FieldBatteries       = "Batteries"
 | 
				
			||||||
	FieldBaromRelativeIn WeatherUpdateField = "BaromRelativeIn"
 | 
						FieldBaromRelativeIn = "BaromRelativeIn"
 | 
				
			||||||
	FieldBaromAbsoluteIn WeatherUpdateField = "BaromAbsoluteIn"
 | 
						FieldBaromAbsoluteIn = "BaromAbsoluteIn"
 | 
				
			||||||
	FieldDewPointF       WeatherUpdateField = "DewPointF"
 | 
						FieldDewPointF       = "DewPointF"
 | 
				
			||||||
	FieldWindChillF      WeatherUpdateField = "WindChillF"
 | 
						FieldWindChillF      = "WindChillF"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (u *WeatherUpdate) GetStationName() string {
 | 
				
			||||||
 | 
						if u.StationConfig != nil {
 | 
				
			||||||
 | 
							return u.StationConfig.Name
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return ""
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user