this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

simplify config

+34 -50
+17 -39
netdata_zulip_bot/config.py
··· 21 21 load_dotenv(env_file) 22 22 logger.info("Loaded configuration from .env file") 23 23 24 - # Load Zulip configuration 24 + # Load Zulip configuration (optional from env, main source should be zuliprc) 25 25 zulip_config = ZulipConfig( 26 - site=os.getenv("ZULIP_SITE", ""), 27 - email=os.getenv("ZULIP_EMAIL", ""), 28 - api_key=os.getenv("ZULIP_API_KEY", ""), 26 + site=os.getenv("ZULIP_SITE"), 27 + email=os.getenv("ZULIP_EMAIL"), 28 + api_key=os.getenv("ZULIP_API_KEY"), 29 29 stream=os.getenv("ZULIP_STREAM", "netdata-alerts"), 30 30 ) 31 31 32 - # Validate required Zulip settings 33 - if not all([zulip_config.site, zulip_config.email, zulip_config.api_key]): 34 - raise ValueError( 35 - "Missing required Zulip configuration. Please set ZULIP_SITE, " 36 - "ZULIP_EMAIL, and ZULIP_API_KEY environment variables." 37 - ) 38 - 39 32 # Load server configuration 40 33 server_config = ServerConfig( 41 34 host=os.getenv("SERVER_HOST", "0.0.0.0"), 42 - port=int(os.getenv("SERVER_PORT", "8443")), 43 - domain=os.getenv("SERVER_DOMAIN", ""), 44 - cert_path=os.getenv("SERVER_CERT_PATH", "./certs"), 45 - enable_mtls=os.getenv("SERVER_ENABLE_MTLS", "true").lower() == "true", 46 - auto_cert=os.getenv("SERVER_AUTO_CERT", "false").lower() == "true", 47 - cert_email=os.getenv("SERVER_CERT_EMAIL", ""), 48 - cert_staging=os.getenv("SERVER_CERT_STAGING", "false").lower() == "true", 49 - acme_port=int(os.getenv("SERVER_ACME_PORT", "80")), 35 + port=int(os.getenv("SERVER_PORT", "8080")), 50 36 ) 51 37 52 - # Validate required server settings 53 - if not server_config.domain: 54 - raise ValueError( 55 - "Missing required server configuration. Please set SERVER_DOMAIN " 56 - "environment variable." 57 - ) 58 - 59 - # Validate auto-cert specific settings 60 - if server_config.auto_cert and not server_config.cert_email: 61 - raise ValueError( 62 - "When SERVER_AUTO_CERT is enabled, SERVER_CERT_EMAIL must be set " 63 - "for Let's Encrypt account registration." 64 - ) 65 - 66 38 logger.info( 67 39 "Configuration loaded", 68 - zulip_site=zulip_config.site, 69 - zulip_email=zulip_config.email, 40 + zulip_site=zulip_config.site or "(from zuliprc)", 41 + zulip_email=zulip_config.email or "(from zuliprc)", 70 42 zulip_stream=zulip_config.stream, 71 43 server_host=server_config.host, 72 44 server_port=server_config.port, 73 - server_domain=server_config.domain, 74 - mtls_enabled=server_config.enable_mtls, 75 - auto_cert=server_config.auto_cert, 76 - cert_staging=server_config.cert_staging, 77 45 ) 78 46 79 47 return zulip_config, server_config ··· 111 79 api_key=config.get('key', ''), 112 80 stream=config.get('stream', 'netdata-alerts'), 113 81 ) 82 + 83 + # Validate required fields from zuliprc 84 + if not all([zulip_config.site, zulip_config.email, zulip_config.api_key]): 85 + missing = [] 86 + if not zulip_config.site: missing.append('site') 87 + if not zulip_config.email: missing.append('email') 88 + if not zulip_config.api_key: missing.append('key') 89 + raise ValueError( 90 + f"Missing required Zulip configuration in {zuliprc_path}: {', '.join(missing)}" 91 + ) 114 92 115 93 logger.info( 116 94 "Loaded Zulip configuration from zuliprc",
+13 -7
netdata_zulip_bot/main.py
··· 36 36 """Create sample configuration files.""" 37 37 38 38 # Sample .env file 39 - env_content = """# Zulip Configuration 40 - ZULIP_SITE=https://yourorg.zulipchat.com 41 - ZULIP_EMAIL=netdata-bot@yourorg.zulipchat.com 42 - ZULIP_API_KEY=your-api-key-here 43 - ZULIP_STREAM=netdata-alerts 44 - 45 - # Server Configuration (HTTP only, TLS handled by reverse proxy) 39 + env_content = """# Server Configuration (HTTP only, TLS handled by reverse proxy) 46 40 SERVER_HOST=0.0.0.0 47 41 SERVER_PORT=8080 42 + 43 + # Optional: Override Zulip stream (default: netdata-alerts) 44 + # ZULIP_STREAM=custom-alerts-stream 48 45 """ 49 46 50 47 with open(".env.sample", 'w') as f: ··· 103 100 # Load configuration 104 101 if args.env_config: 105 102 zulip_config, server_config = load_config() 103 + # Validate that required Zulip fields are provided via environment 104 + if not all([zulip_config.site, zulip_config.email, zulip_config.api_key]): 105 + missing = [] 106 + if not zulip_config.site: missing.append('ZULIP_SITE') 107 + if not zulip_config.email: missing.append('ZULIP_EMAIL') 108 + if not zulip_config.api_key: missing.append('ZULIP_API_KEY') 109 + raise ValueError( 110 + f"When using --env-config, these environment variables are required: {', '.join(missing)}" 111 + ) 106 112 else: 107 113 zulip_config = load_zuliprc_config(args.zuliprc) 108 114 # Still need server config from environment
+4 -4
netdata_zulip_bot/models.py
··· 71 71 72 72 class ZulipConfig(BaseModel): 73 73 """Zulip bot configuration.""" 74 - site: str 75 - email: str 76 - api_key: str 77 - stream: str 74 + site: Optional[str] = None 75 + email: Optional[str] = None 76 + api_key: Optional[str] = None 77 + stream: str = "netdata-alerts" 78 78 79 79 model_config = ConfigDict(env_prefix="ZULIP_") 80 80