wallaroo.notify
1class Notification: 2 def to_json(self): 3 raise NotImplemented() 4 5 6class Email(Notification): 7 def __init__(self, to): 8 self.args = {"to": to} 9 10 def to_json(self): 11 return self.args 12 13 @classmethod 14 def from_json(cls, json): 15 return Email(json["to"]) 16 17 18def to_json(notifications): 19 emails = [n for n in notifications if isinstance(n, Email)] 20 return {"email": [n.to_json() for n in emails]} 21 22 23def from_json(json): 24 return [Email.from_json(e) for e in json["email"]] 25 26 27class AlertConfiguration: 28 def __init__(self, name, expression, notifications): 29 self.name = name 30 self.expression = expression 31 self.notifications = notifications 32 33 @classmethod 34 def from_json(Cls, json): 35 return Cls( 36 json["name"], 37 json["expression"], 38 from_json(json["notifications"]), 39 ) 40 41 def to_json(self): 42 return { 43 "name": self.name, 44 "expression": self.expression, 45 "notifications": to_json(self.notifications), 46 }
class
Notification:
def
to_json(notifications):
def
from_json(json):
class
AlertConfiguration:
28class AlertConfiguration: 29 def __init__(self, name, expression, notifications): 30 self.name = name 31 self.expression = expression 32 self.notifications = notifications 33 34 @classmethod 35 def from_json(Cls, json): 36 return Cls( 37 json["name"], 38 json["expression"], 39 from_json(json["notifications"]), 40 ) 41 42 def to_json(self): 43 return { 44 "name": self.name, 45 "expression": self.expression, 46 "notifications": to_json(self.notifications), 47 }