]>
git.proxmox.com Git - pve-ha-manager.git/blob - src/PVE/API2/HA/Status.pm
1 package PVE
::API2
::HA
::Status
;
10 use PVE
::JSONSchema
qw(get_standard_option);
11 use PVE
::RPCEnvironment
;
12 use PVE
::HA
::Env
::PVE2
;
16 use base
qw(PVE::RESTHandler);
18 my $nodename = PVE
::INotify
::nodename
();
20 my $timestamp_to_status = sub {
21 my ($ctime, $timestamp) = @_;
23 my $tdiff = $ctime - $timestamp;
25 return "old timestamp - dead?";
26 } elsif ($tdiff < -2) {
27 return "detected time drift!";
33 __PACKAGE__-
>register_method ({
37 permissions
=> { user
=> 'all' },
38 description
=> "Directory index.",
40 additionalProperties
=> 0,
49 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
55 { name
=> 'current' },
56 { name
=> 'manager_status' },
62 __PACKAGE__-
>register_method ({
66 description
=> "Get HA manger status.",
68 check
=> ['perm', '/', [ 'Sys.Audit' ]],
71 additionalProperties
=> 0,
74 returns
=> { type
=> 'array' },
80 if (PVE
::Cluster
::check_cfs_quorum
(1)) {
81 push @$res, { id
=> 'quorum', type
=> 'quorum',
82 node
=> $nodename, status
=> "OK", quorate
=> 1 };
84 push @$res, { id
=> 'quorum', type
=> 'quorum', node
=> $nodename,
85 status
=> "No quorum on node '$nodename'!", quorate
=> 0 };
88 my $haenv = PVE
::HA
::Env
::PVE2-
>new($nodename);
90 my $status = $haenv->read_manager_status();
92 my $ctime = $haenv->get_time();
94 if (defined($status->{master_node
}) && defined($status->{timestamp
})) {
95 my $master = $status->{master_node
};
96 my $status_str = &$timestamp_to_status($ctime, $status->{timestamp
});
97 my $time_str = localtime($status->{timestamp
});
98 my $status_text = "$master ($status_str, $time_str)";
99 push @$res, { id
=> 'master', type
=> 'master', node
=> $master,
100 status
=> $status_text, timestamp
=> $status->{timestamp
} };
103 # compute active services for all nodes
104 my $active_count = {};
105 foreach my $sid (sort keys %{$status->{service_status
}}) {
106 my $sd = $status->{service_status
}->{$sid};
107 next if !$sd->{node
};
108 $active_count->{$sd->{node
}} = 0 if !defined($active_count->{$sd->{node
}});
109 my $req_state = $sd->{state};
110 next if !defined($req_state);
111 next if $req_state eq 'stopped';
112 next if $req_state eq 'freeze';
113 $active_count->{$sd->{node
}}++;
116 foreach my $node (sort keys %{$status->{node_status
}}) {
117 my $lrm_status = $haenv->read_lrm_status($node);
118 my $id = "lrm:$node";
119 if (!$lrm_status->{timestamp
}) {
120 push @$res, { id
=> $id, type
=> 'lrm', node
=> $node,
121 status
=> "$node (unable to read lrm status)"};
123 my $status_str = &$timestamp_to_status($ctime, $lrm_status->{timestamp
});
124 if ($status_str eq 'active') {
125 my $lrm_mode = $lrm_status->{mode
} || 'active';
126 my $lrm_state = $lrm_status->{state} || 'unknown';
127 if ($lrm_mode ne 'active') {
128 $status_str = "$lrm_mode mode";
130 if ($lrm_state eq 'wait_for_agent_lock' && !$active_count->{$node}) {
131 $status_str = 'idle';
133 $status_str = $lrm_state;
138 my $time_str = localtime($lrm_status->{timestamp
});
139 my $status_text = "$node ($status_str, $time_str)";
140 push @$res, { id
=> $id, type
=> 'lrm', node
=> $node,
141 status
=> $status_text, timestamp
=> $lrm_status->{timestamp
} };
145 foreach my $sid (sort keys %{$status->{service_status
}}) {
146 my $d = $status->{service_status
}->{$sid};
147 push @$res, { id
=> "service:$sid", type
=> 'service', sid
=> $sid,
148 node
=> $d->{node
}, status
=> "$sid ($d->{node}, $d->{state})" };
154 __PACKAGE__-
>register_method ({
155 name
=> 'manager_status',
156 path
=> 'manager_status',
158 description
=> "Get full HA manger status, including LRM status.",
160 check
=> ['perm', '/', [ 'Sys.Audit' ]],
163 additionalProperties
=> 0,
166 returns
=> { type
=> 'object' },
170 my $haenv = PVE
::HA
::Env
::PVE2-
>new($nodename);
172 my $status = $haenv->read_manager_status();
174 my $data = { manager_status
=> $status };
178 quorate
=> PVE
::Cluster
::check_cfs_quorum
(1),
181 foreach my $node (sort keys %{$status->{node_status
}}) {
182 my $lrm_status = $haenv->read_lrm_status($node);
183 $data->{lrm_status
}->{$node} = $lrm_status;