]> git.proxmox.com Git - pve-ha-manager.git/blobdiff - src/PVE/HA/NodeStatus.pm
manager: send notifications via new notification module
[pve-ha-manager.git] / src / PVE / HA / NodeStatus.pm
index ee5be8e1eec40031b4b7c0ab5310238484c084c7..b264a367429b22c80757473ab02d02b9466b010c 100644 (file)
@@ -188,35 +188,45 @@ sub update {
    }
 }
 
-# assembles a commont text for fence emails
-my $send_fence_state_email = sub {
-    my ($self, $subject_prefix, $subject, $node) = @_;
-
-    my $haenv = $self->{haenv};
-
-    my $mail_text = <<EOF
-The node '$node' failed and needs manual intervention.
+my $body_template = <<EOT;
+{{#verbatim}}
+The node '{{node}}' failed and needs manual intervention.
 
-The PVE HA manager tries  to fence it and recover the
-configured HA resources to a healthy node if possible.
+The PVE HA manager tries  to fence it and recover the configured HA resources to
+a healthy node if possible.
 
-Current fence status:  $subject_prefix
-$subject
+Current fence status: {{subject-prefix}}
+{{subject}}
+{{/verbatim}}
 
+{{heading-2 "Overall Cluster status:"}}
+{{object status-data}}
+EOT
 
-Overall Cluster status:
------------------------
+my $subject_template = "{{subject-prefix}}: {{subject}}";
 
-EOF
-;
-    my $mail_subject = $subject_prefix . ': ' . $subject;
+# assembles a commont text for fence emails
+my $send_fence_state_email = sub {
+    my ($self, $subject_prefix, $subject, $node) = @_;
 
+    my $haenv = $self->{haenv};
     my $status = $haenv->read_manager_status();
-    my $data = { manager_status => $status, node_status => $self->{status} };
-
-    $mail_text .= to_json($data, { pretty => 1, canonical => 1});
 
-    $haenv->sendmail($mail_subject, $mail_text);
+    my $notification_properties = {
+       "status-data"    => {
+           manager_status => $status,
+           node_status    => $self->{status}
+       },
+       "node"           => $node,
+       "subject-prefix" => $subject_prefix,
+       "subject"        => $subject,
+    };
+
+    $haenv->send_notification(
+       $subject_template,
+       $body_template,
+       $notification_properties
+    );
 };