소스 검색

fix ntfy config

zehe 3 달 전
부모
커밋
8f67d7b2b5
3개의 변경된 파일22개의 추가작업 그리고 24개의 파일을 삭제
  1. 4 4
      README.md
  2. 10 19
      main.py
  3. 8 1
      test.py

+ 4 - 4
README.md

@@ -391,13 +391,13 @@ The service binds only to localhost (127.0.0.1:1127) and is accessed through you
 2. **Notification failures**:
    ```bash
    # Test dschep/ntfy installation and configuration
-   NTFY_CONFIG=/etc/emergency-access/ntfy.yml ntfy send "test message"
+   ntfy -c /etc/emergency-access/ntfy.yml send "test message"
    
    # Check ntfy configuration
    cat /etc/emergency-access/ntfy.yml
    
    # Test specific backend
-   NTFY_CONFIG=/etc/emergency-access/ntfy.yml ntfy -b matrix_sec send "test message"
+   ntfy -c /etc/emergency-access/ntfy.yml -b matrix_sec send "test message"
    ```
 
 3. **File permission errors**:
@@ -417,8 +417,8 @@ Test your setup before deployment:
 sudo -u emergency-access /opt/emergency-access/venv/bin/python /opt/emergency-access/main.py --validate
 
 # Test notifications manually with your backend
-NTFY_CONFIG=/etc/emergency-access/ntfy.yml ntfy -b matrix_sec send "Test notification"
-NTFY_CONFIG=/etc/emergency-access/ntfy.yml ntfy -b pushover_emergency send "Test emergency notification"
+ntfy -c /etc/emergency-access/ntfy.yml -b matrix_sec send "Test notification"
+ntfy -c /etc/emergency-access/ntfy.yml -b pushover_emergency send "Test emergency notification"
 ```
 
 ## Development

+ 10 - 19
main.py

@@ -68,26 +68,17 @@ def send_ntfy_notification(backends: List[str], message: str, title: str = None)
             # Import ntfy here to avoid import issues during startup
             import ntfy
 
-            # Set the ntfy config file path
-            old_config = os.environ.get('NTFY_CONFIG')
-            os.environ['NTFY_CONFIG'] = config.ntfy_config_path
+            # Load the ntfy config file
+            ntfy_config = ntfy.load_config(config.ntfy_config_path)
 
-            try:
-                # Send notification using the backend name from our config file
-                if title:
-                    ntfy.notify(message, title=title, backend=backend)
-                else:
-                    ntfy.notify(message, backend=backend)
-
-                successful_backends.append(backend)
-                logger.info(f"Notification sent successfully via {backend}")
-
-            finally:
-                # Restore original config
-                if old_config:
-                    os.environ['NTFY_CONFIG'] = old_config
-                elif 'NTFY_CONFIG' in os.environ:
-                    del os.environ['NTFY_CONFIG']
+            # Send notification using the backend name from our config file
+            if title:
+                ntfy.notify(message, title=title, backend=backend, config=ntfy_config)
+            else:
+                ntfy.notify(message, backend=backend, config=ntfy_config)
+
+            successful_backends.append(backend)
+            logger.info(f"Notification sent successfully via {backend}")
 
         except ImportError:
             logger.error(f"ntfy package not available for backend {backend}")

+ 8 - 1
test.py

@@ -100,13 +100,20 @@ class EmergencyAccessTester:
         """Test ntfy backend connectivity"""
         success = True
 
-        # Test importing ntfy
+        # Test importing ntfy and loading config
         try:
             import ntfy
             self.log_test("ntfy Import", True, "dschep/ntfy package available")
+
+            # Test loading the ntfy config file
+            ntfy_config = ntfy.load_config(self.config.ntfy_config_path)
+            self.log_test("ntfy Config Load", True, f"Config loaded from {self.config.ntfy_config_path}")
         except ImportError:
             self.log_test("ntfy Import", False, "dschep/ntfy package not installed")
             return False
+        except Exception as e:
+            self.log_test("ntfy Config Load", False, f"Failed to load config: {str(e)}")
+            return False
 
         # Test key notification backends
         for backend in self.config.ntfy_backends_key: