Switches to YAML for config file
							parent
							
								
									286d3f15d3
								
							
						
					
					
						commit
						879ee5004f
					
				
								
									
									
										
											19
										
									
									go/build.sh
									
									
									
									
								
								
							
							
										
											19
										
									
									go/build.sh
									
									
									
									
								|  | @ -1,3 +1,20 @@ | |||
| #!/usr/bin/env bash | ||||
| 
 | ||||
| go build -o jilo-agent main.go | ||||
| ### | ||||
| # Jilo Agent building script | ||||
| # | ||||
| # Description: Building script for Jilo Agent | ||||
| # Author: Yasen Pramatarov | ||||
| # License: GPLv2 | ||||
| # Project URL: https://lindeas.com/jilo | ||||
| # Year: 2024 | ||||
| # Version: 0.1 | ||||
| # | ||||
| # requirements: | ||||
| # - go | ||||
| # - upx | ||||
| ### | ||||
| 
 | ||||
| CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o jilo-agent main.go | ||||
| upx --best --lzma -o jilo-agent-upx jilo-agent | ||||
| mv jilo-agent-upx jilo-agent | ||||
|  |  | |||
|  | @ -0,0 +1,5 @@ | |||
| module jilo-agent | ||||
| 
 | ||||
| go 1.22.6 | ||||
| 
 | ||||
| require gopkg.in/yaml.v2 v2.4.0 // indirect | ||||
|  | @ -0,0 +1,3 @@ | |||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||||
| gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= | ||||
| gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= | ||||
|  | @ -0,0 +1,15 @@ | |||
| ## | ||||
| # configuration file for Jilo Agent | ||||
| ## | ||||
| 
 | ||||
| # the port on which the agent will listen | ||||
| agent_port: 8081 | ||||
| 
 | ||||
| # the port we check for nginx | ||||
| nginx_port: 80 | ||||
| 
 | ||||
| # URL to the Jicofo stats API | ||||
| jicofo_stats_url: "http://localhost:8888/stats" | ||||
| 
 | ||||
| # URL to the JVB stats API | ||||
| jvb_stats_url: "http://localhost:8080/colibri/stats" | ||||
|  | @ -1,6 +0,0 @@ | |||
| { | ||||
|     "agent_port": 8081, | ||||
|     "nginx_port": 80, | ||||
|     "jicofo_stats_url": "http://localhost:8888/stats", | ||||
|     "jvb_stats_url": "http://localhost:8080/colibri/stats" | ||||
| } | ||||
								
									
									
										
											17
										
									
									go/main.go
									
									
									
									
								
								
							
							
										
											17
										
									
									go/main.go
									
									
									
									
								|  | @ -14,6 +14,7 @@ package main | |||
| import ( | ||||
|     "encoding/json" | ||||
|     "fmt" | ||||
|     "gopkg.in/yaml.v2" | ||||
|     "io/ioutil" | ||||
|     "log" | ||||
|     "net/http" | ||||
|  | @ -25,11 +26,11 @@ import ( | |||
| 
 | ||||
| // Config holds the structure of the configuration file
 | ||||
| type Config struct { | ||||
|     AgentPort		int	`json:"agent_port"` | ||||
|     NginxPort		int	`json:"nginx_port"` | ||||
|     ProsodyPort		int	`json:"prosody_port"` | ||||
|     JicofoStatsURL	string	`json:"jicofo_stats_url"` | ||||
|     JVBStatsURL		string	`json:"jvb_stats_url"` | ||||
|     AgentPort		int	`yaml:"agent_port"` | ||||
|     NginxPort		int	`yaml:"nginx_port"` | ||||
|     ProsodyPort		int	`yaml:"prosody_port"` | ||||
|     JicofoStatsURL	string	`yaml:"jicofo_stats_url"` | ||||
|     JVBStatsURL		string	`yaml:"jvb_stats_url"` | ||||
| } | ||||
| 
 | ||||
| // NginxData holds the nginx data structure for the API response to /nginx
 | ||||
|  | @ -103,7 +104,7 @@ func getJitsiAPIData(service string, url string) map[string]interface{} { | |||
|     return result | ||||
| } | ||||
| 
 | ||||
| // loadConfig loads the configuration from a JSON config file
 | ||||
| // loadConfig loads the configuration from a YAML config file
 | ||||
| func loadConfig(filename string) (Config) { | ||||
| 
 | ||||
|     // default config values
 | ||||
|  | @ -129,7 +130,7 @@ func loadConfig(filename string) (Config) { | |||
|         return config | ||||
|     } | ||||
| 
 | ||||
|     if err := json.Unmarshal(bytes, &config); err != nil { | ||||
|     if err := yaml.Unmarshal(bytes, &config); err != nil { | ||||
|         log.Printf("Error parsing the config file. Using default values.") | ||||
|     } | ||||
| 
 | ||||
|  | @ -181,7 +182,7 @@ func jvbHandler(config Config, w http.ResponseWriter, r *http.Request) { | |||
| func main() { | ||||
| 
 | ||||
|     // load the configuration
 | ||||
|     config := loadConfig("jilo-agent.json") | ||||
|     config := loadConfig("jilo-agent.conf") | ||||
| 
 | ||||
|     // endpoints
 | ||||
|     http.HandleFunc("/nginx", func(w http.ResponseWriter, r *http.Request) { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue