0
0
Fork 0
mirror of https://github.com/healthchecks/healthchecks.git synced 2025-04-11 15:51:19 +00:00

Fix the shell integration to use Flip.new_status

This commit is contained in:
Pēteris Caune 2024-04-12 14:10:34 +03:00
parent 8372abf019
commit a6b8f4c71e
No known key found for this signature in database
GPG key ID: E28D7679E9A9EDE2
2 changed files with 11 additions and 8 deletions

View file

@ -18,7 +18,9 @@ class NotifyTestCase(BaseTestCase):
self, kind: str, value: str, status: str = "down", email_verified: bool = True
) -> None:
self.check = Check(project=self.project)
self.check.status = status
# Transport classes should use flip.new_status,
# so the status "paused" should not appear anywhere
self.check.status = "paused"
self.check.last_ping = now() - td(minutes=61)
self.check.save()

View file

@ -194,13 +194,14 @@ class Email(Transport):
class Shell(Transport):
def prepare(self, template: str, check: Check) -> str:
def prepare(self, template: str, flip: Flip) -> str:
"""Replace placeholders with actual values."""
check = flip.owner
ctx = {
"$CODE": str(check.code),
"$STATUS": check.status,
"$NOW": now().replace(microsecond=0).isoformat(),
"$STATUS": flip.new_status,
"$NOW": flip.created.replace(microsecond=0).isoformat(),
"$NAME": check.name,
"$TAGS": check.tags,
}
@ -219,16 +220,16 @@ class Shell(Transport):
return False
def notify(self, check: Check, notification: Notification) -> None:
def notify_flip(self, flip: Flip, notification: Notification) -> None:
if not settings.SHELL_ENABLED:
raise TransportError("Shell commands are not enabled")
if check.status == "up":
if flip.new_status == "up":
cmd = self.channel.shell.cmd_up
elif check.status == "down":
elif flip.new_status == "down":
cmd = self.channel.shell.cmd_down
cmd = self.prepare(cmd, check)
cmd = self.prepare(cmd, flip)
code = os.system(cmd)
if code != 0: