mirror of
https://github.com/recklessop/Zerto_Exporter.git
synced 2026-07-05 08:43:14 -04:00
Refactor to prometheus_client, JSON logging, and codebase cleanup
- Replace file-based metrics and HTTP server with prometheus_client (Gauge + start_http_server), eliminating file I/O race conditions - Fix ThreadProbe and thread restart lambda bugs - Switch logging from RotatingFileHandler to JSON stdout for fluentd/Loki - Add PYTHONUNBUFFERED=1 to Dockerfile for immediate container log output - Upgrade base image from python:3.12.3-slim to python:3.13-slim - Upgrade pyvmomi to 9.0.0.0; pin pydantic>=2.9.0 and typing_extensions>=4.12.2 to use pre-built Python 3.13 wheels (removes Rust toolchain from build) - Remove unused packages: boto3, botocore, s3transfer, jmespath, redis, docopt, pyflakes, posthog - Remove unused imports (Posthog, CaseInsensitiveDict) and dead variables (callhomestats, local_site_info, lastStats) - Fix service_profile() NameError (siteidentifier -> serviceProfileIdentifier) - Remove bare print() in zvma.py __authhandler__, replace with self.log.info() - Remove all commented-out PostHog blocks from zvma10/zvma.py - Delete legacy zvma9_7/ module and app/logs/ directory - Remove deprecated 'version: 3.3' from docker-compose.yml Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+3
-31
@@ -17,7 +17,6 @@ from dateutil import parser
|
||||
from typing import List, Dict, Tuple, Union, Any, Optional
|
||||
from requests.structures import CaseInsensitiveDict
|
||||
from logging.handlers import RotatingFileHandler
|
||||
#from posthog import Posthog
|
||||
import uuid
|
||||
from requests import Request, Session
|
||||
from .version import VERSION
|
||||
@@ -74,12 +73,6 @@ class zvmsite:
|
||||
# Get UUID
|
||||
self.uuid = self.load_or_generate_uuid()
|
||||
|
||||
# Posthog stats setup
|
||||
#if self.stats:
|
||||
# self.setup_posthog()
|
||||
# self.posthog.capture(self.uuid, 'ZVMA10 Python Module Loaded')
|
||||
# self.log.debug("Sent PostHog Hook")
|
||||
|
||||
def __authhandler__(self) -> None:
|
||||
self.log.info(f"Log Level set to {self.LOGLEVEL}")
|
||||
if not self.__connected__:
|
||||
@@ -102,9 +95,11 @@ class zvmsite:
|
||||
}
|
||||
if self.grant_type == "client_credentials":
|
||||
data["client_secret"] = self.client_secret
|
||||
data["scope"] = "openid"
|
||||
else:
|
||||
data["username"] = self.username
|
||||
data["password"] = self.password
|
||||
data["scope"] = "openid"
|
||||
|
||||
|
||||
uri = self.construct_url(path="auth/realms/zerto/protocol/openid-connect/token")
|
||||
@@ -129,7 +124,6 @@ class zvmsite:
|
||||
self.expiresIn -= 10
|
||||
else:
|
||||
self.log.info("Authentication thread is already running")
|
||||
print(f"Auth thread already running")
|
||||
|
||||
def is_authenticated(self) -> bool:
|
||||
# Assuming self.token is the authentication token and it's set upon successful authentication
|
||||
@@ -172,11 +166,6 @@ class zvmsite:
|
||||
file.write(new_uuid)
|
||||
return new_uuid
|
||||
|
||||
#def setup_posthog(self) -> None:
|
||||
# self.posthog = Posthog(project_api_key='phc_HflqUkx9majhzm8DZva8pTwXFRnOn99onA9xPpK5HaQ', host='https://posthog.jpaul.io')
|
||||
# self.posthog.debug = True
|
||||
# self.posthog.identify(distinct_id=self.uuid)
|
||||
|
||||
def construct_url(self, path="", params=None) -> str:
|
||||
full_url = f"{self.base_url}/{path}"
|
||||
if params:
|
||||
@@ -235,23 +224,6 @@ class zvmsite:
|
||||
response.raise_for_status()
|
||||
self.log.debug(f'API Request: {method} - {url}')
|
||||
|
||||
# Posthog stats setup
|
||||
#if self.stats:
|
||||
# temp_base, temp_path = self.deconstruct_url(url)
|
||||
# self.posthog.capture( self.uuid, 'API REQUEST',
|
||||
# {
|
||||
# "url": temp_base,
|
||||
# "port": self.port,
|
||||
# "endpoint": temp_path,
|
||||
# "method": method,
|
||||
# "response_time_ms": int(elapsed_time_ms),
|
||||
# "verify_ssl": self.verify_ssl,
|
||||
# "grant_type": self.grant_type,
|
||||
# "status_code": str(response.status_code),
|
||||
# "sdk_version": self.__version__
|
||||
# })
|
||||
# self.log.debug("Sent PostHog Hook")
|
||||
|
||||
return response.json()
|
||||
except requests.exceptions.RequestException as e:
|
||||
self.log.error(f"Error while sending API request: {e}")
|
||||
@@ -794,7 +766,7 @@ class zvmsite:
|
||||
return self.make_api_request("GET", uri, headers=self.apiheader)
|
||||
|
||||
def service_profile(self, serviceProfileIdentifier=None) -> Dict[str, Any]:
|
||||
if siteidentifier is None:
|
||||
if serviceProfileIdentifier is None:
|
||||
self.log.error("Service Profile identifier is required for get site function.")
|
||||
raise ValueError("Service Profile identifier is required.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user