You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wasted some hours trying to get this API work on my fork. The requirements are frozen, so it needs a fix right away. I wanted to use Events API, but it does nor produce usable return type. It is all kind of awkward.
For my purpose I wrote my code from scrap:
importosimportrequestsfromenumimportEnumfromtypingimportOptional, Dict, AnyimportloggingclassZendutyAlertType(Enum):
CRITICAL="critical"ERROR="error"RESOLVED="resolved"classZendutyClient:
""" A class to handle sending alerts to Zenduty service. """def__init__(self, api_key: Optional[str] =None):
""" Initialize the ZendutyAlerts client. Args: api_key: Zenduty API key. If not provided, will look for ZENDUTY_API_KEY env variable """self.api_key=api_keyoros.getenv("ZENDUTY_API_KEY")
ifnotself.api_key:
raiseValueError(
"ZENDUTY_API_KEY must be provided or set as environment variable"
)
self.logger=logging.getLogger(__name__)
self.base_url="https://www.zenduty.com/api/events"defsend_alert(
self,
*,
alert_type: ZendutyAlertType,
message: str,
entity_id: str,
summary: str,
payload: Optional[Dict[str, Any]] =None,
urls: Optional[Dict[str, str]] =None,
):
try:
request_data: Dict[str, Any] = {
"alert_type": alert_type.value,
"entity_id": entity_id,
"message": message,
"summary": summary,
}
ifpayloadisnotNone:
request_data["payload"] =payloadifurlsisnotNone:
request_data["urls"] = [
{"link_text": k, "link_url": v} fork, vinurls.items()
]
url=f"{self.base_url}/{self.api_key}/"response=requests.post(
url, json=request_data, headers={"Content-Type": "application/json"}
)
ifself.logger.isEnabledFor(logging.DEBUG):
self.logger.debug(f"Request data: {request_data}")
self.logger.debug(f"Response data: {response.json()}")
returnresponseexceptrequests.exceptions.RequestExceptionase:
self.logger.error(f"Failed to send alert to Zenduty: {str(e)}")
returnFalseexceptExceptionase:
self.logger.error(f"Error sending alert: {str(e)}")
returnFalse
The text was updated successfully, but these errors were encountered:
I wasted some hours trying to get this API work on my fork. The requirements are frozen, so it needs a fix right away. I wanted to use Events API, but it does nor produce usable return type. It is all kind of awkward.
For my purpose I wrote my code from scrap:
The text was updated successfully, but these errors were encountered: