]> git.proxmox.com Git - pve-manager.git/blame - PVE/CLI/pve6to7.pm
vdzump: log with what retention settings we prune
[pve-manager.git] / PVE / CLI / pve6to7.pm
CommitLineData
4177a14d
TL
1package PVE::CLI::pve6to7;
2
3use strict;
4use warnings;
5
6use PVE::API2::APT;
7use PVE::API2::Ceph;
8use PVE::API2::LXC;
9use PVE::API2::Qemu;
10use PVE::API2::Certificates;
11
12use PVE::Ceph::Tools;
13use PVE::Cluster;
14use PVE::Corosync;
15use PVE::INotify;
16use PVE::JSONSchema;
17use PVE::RPCEnvironment;
18use PVE::Storage;
19use PVE::Tools qw(run_command);
20use PVE::QemuServer;
e522a2db 21use PVE::VZDump::Common;
4177a14d
TL
22
23use Term::ANSIColor;
24
25use PVE::CLIHandler;
26
27use base qw(PVE::CLIHandler);
28
29my $nodename = PVE::INotify::nodename();
30
31sub setup_environment {
32 PVE::RPCEnvironment->setup_default_cli_env();
33}
34
35my $min_pve_major = 6;
36my $min_pve_minor = 4;
37my $min_pve_pkgrel = 1;
38
39my $counters = {
40 pass => 0,
41 skip => 0,
42 warn => 0,
43 fail => 0,
44};
45
46my $log_line = sub {
47 my ($level, $line) = @_;
48
49 $counters->{$level}++ if defined($level) && defined($counters->{$level});
50
51 print uc($level), ': ' if defined($level);
52 print "$line\n";
53};
54
55sub log_pass {
56 print color('green');
57 $log_line->('pass', @_);
58 print color('reset');
59}
60
61sub log_info {
62 $log_line->('info', @_);
63}
64sub log_skip {
65 $log_line->('skip', @_);
66}
67sub log_warn {
68 print color('yellow');
69 $log_line->('warn', @_);
70 print color('reset');
71}
72sub log_fail {
73 print color('red');
74 $log_line->('fail', @_);
75 print color('reset');
76}
77
78my $print_header_first = 1;
79sub print_header {
80 my ($h) = @_;
81 print "\n" if !$print_header_first;
82 print "= $h =\n\n";
83 $print_header_first = 0;
84}
85
86my $get_systemd_unit_state = sub {
87 my ($unit) = @_;
88
89 my $state;
90 my $filter_output = sub {
91 $state = shift;
92 chomp $state;
93 };
94 eval {
95 run_command(['systemctl', 'is-enabled', "$unit"], outfunc => $filter_output, noerr => 1);
96 return if !defined($state);
97 run_command(['systemctl', 'is-active', "$unit"], outfunc => $filter_output, noerr => 1);
98 };
99
100 return $state // 'unknown';
101};
102my $log_systemd_unit_state = sub {
103 my ($unit, $no_fail_on_inactive) = @_;
104
105 my $log_method = \&log_warn;
106
107 my $state = $get_systemd_unit_state->($unit);
108 if ($state eq 'active') {
109 $log_method = \&log_pass;
110 } elsif ($state eq 'inactive') {
111 $log_method = $no_fail_on_inactive ? \&log_warn : \&log_fail;
112 } elsif ($state eq 'failed') {
113 $log_method = \&log_fail;
114 }
115
116 $log_method->("systemd unit '$unit' is in state '$state'");
117};
118
119my $versions;
120my $get_pkg = sub {
121 my ($pkg) = @_;
122
123 $versions = eval { PVE::API2::APT->versions({ node => $nodename }) } if !defined($versions);
124
125 if (!defined($versions)) {
126 my $msg = "unable to retrieve package version information";
127 $msg .= "- $@" if $@;
128 log_fail("$msg");
129 return undef;
130 }
131
132 my $pkgs = [ grep { $_->{Package} eq $pkg } @$versions ];
133 if (!defined $pkgs || $pkgs == 0) {
134 log_fail("unable to determine installed $pkg version.");
135 return undef;
136 } else {
137 return $pkgs->[0];
138 }
139};
140
141sub check_pve_packages {
142 print_header("CHECKING VERSION INFORMATION FOR PVE PACKAGES");
143
144 print "Checking for package updates..\n";
145 my $updates = eval { PVE::API2::APT->list_updates({ node => $nodename }); };
146 if (!defined($updates)) {
147 log_warn("$@") if $@;
148 log_fail("unable to retrieve list of package updates!");
149 } elsif (@$updates > 0) {
150 my $pkgs = join(', ', map { $_->{Package} } @$updates);
151 log_warn("updates for the following packages are available:\n $pkgs");
152 } else {
153 log_pass("all packages uptodate");
154 }
155
156 print "\nChecking proxmox-ve package version..\n";
157 if (defined(my $proxmox_ve = $get_pkg->('proxmox-ve'))) {
158 my $min_pve_ver = "$min_pve_major.$min_pve_minor-$min_pve_pkgrel";
159
160 my ($maj, $min, $pkgrel) = $proxmox_ve->{OldVersion} =~ m/^(\d+)\.(\d+)-(\d+)/;
161
162 my $upgraded = 0;
163
164 if ($maj > $min_pve_major) {
165 log_pass("already upgraded to Proxmox VE " . ($min_pve_major + 1));
166 $upgraded = 1;
167 } elsif ($maj >= $min_pve_major && $min >= $min_pve_minor && $pkgrel >= $min_pve_pkgrel) {
168 log_pass("proxmox-ve package has version >= $min_pve_ver");
169 } else {
170 log_fail("proxmox-ve package is too old, please upgrade to >= $min_pve_ver!");
171 }
172
173 my ($krunning, $kinstalled) = (qr/5\.11/, 'pve-kernel-5.11');
174 if (!$upgraded) {
175 ($krunning, $kinstalled) = (qr/5\.(?:4|11)/, 'pve-kernel-4.15');
176 }
177
178 print "\nChecking running kernel version..\n";
179 my $kernel_ver = $proxmox_ve->{RunningKernel};
180 if (!defined($kernel_ver)) {
181 log_fail("unable to determine running kernel version.");
182 } elsif ($kernel_ver =~ /^$krunning/) {
183 log_pass("expected running kernel '$kernel_ver'.");
184 } elsif ($get_pkg->($kinstalled)) {
185 log_warn("expected kernel '$kinstalled' intalled but not yet rebooted!");
186 } else {
187 log_warn("unexpected running and installed kernel '$kernel_ver'.");
188 }
189 } else {
190 log_fail("proxmox-ve package not found!");
191 }
192}
193
194
195sub check_storage_health {
196 print_header("CHECKING CONFIGURED STORAGES");
197 my $cfg = PVE::Storage::config();
198
199 my $ctime = time();
200
201 my $info = PVE::Storage::storage_info($cfg);
202
203 foreach my $storeid (keys %$info) {
204 my $d = $info->{$storeid};
205 if ($d->{enabled}) {
206 if ($d->{type} eq 'sheepdog') {
207 log_fail("storage '$storeid' of type 'sheepdog' is enabled - experimental sheepdog support dropped in PVE 6")
208 } elsif ($d->{active}) {
209 log_pass("storage '$storeid' enabled and active.");
210 } else {
211 log_warn("storage '$storeid' enabled but not active!");
212 }
213 } else {
214 log_skip("storage '$storeid' disabled.");
215 }
216 }
217}
218
219sub check_cluster_corosync {
220 print_header("CHECKING CLUSTER HEALTH/SETTINGS");
221
222 if (!PVE::Corosync::check_conf_exists(1)) {
223 log_skip("standalone node.");
224 return;
225 }
226
227 $log_systemd_unit_state->('pve-cluster.service');
228 $log_systemd_unit_state->('corosync.service');
229
230 if (PVE::Cluster::check_cfs_quorum(1)) {
231 log_pass("Cluster Filesystem is quorate.");
232 } else {
233 log_fail("Cluster Filesystem readonly, lost quorum?!");
234 }
235
236 my $conf = PVE::Cluster::cfs_read_file('corosync.conf');
237 my $conf_nodelist = PVE::Corosync::nodelist($conf);
238 my $node_votes = 0;
239
240 print "\nAnalzying quorum settings and state..\n";
241 if (!defined($conf_nodelist)) {
242 log_fail("unable to retrieve nodelist from corosync.conf");
243 } else {
244 if (grep { $conf_nodelist->{$_}->{quorum_votes} != 1 } keys %$conf_nodelist) {
245 log_warn("non-default quorum_votes distribution detected!");
246 }
247 map { $node_votes += $conf_nodelist->{$_}->{quorum_votes} // 0 } keys %$conf_nodelist;
248 }
249
250 my ($expected_votes, $total_votes);
251 my $filter_output = sub {
252 my $line = shift;
253 ($expected_votes) = $line =~ /^Expected votes:\s*(\d+)\s*$/
254 if !defined($expected_votes);
255 ($total_votes) = $line =~ /^Total votes:\s*(\d+)\s*$/
256 if !defined($total_votes);
257 };
258 eval {
259 run_command(['corosync-quorumtool', '-s'], outfunc => $filter_output, noerr => 1);
260 };
261
262 if (!defined($expected_votes)) {
263 log_fail("unable to get expected number of votes, setting to 0.");
264 $expected_votes = 0;
265 }
266 if (!defined($total_votes)) {
267 log_fail("unable to get expected number of votes, setting to 0.");
268 $total_votes = 0;
269 }
270
271 my $cfs_nodelist = PVE::Cluster::get_clinfo()->{nodelist};
272 my $offline_nodes = grep { $cfs_nodelist->{$_}->{online} != 1 } keys %$cfs_nodelist;
273 if ($offline_nodes > 0) {
274 log_fail("$offline_nodes nodes are offline!");
275 }
276
277 my $qdevice_votes = 0;
278 if (my $qdevice_setup = $conf->{main}->{quorum}->{device}) {
279 $qdevice_votes = $qdevice_setup->{votes} // 1;
280 }
281
282 log_info("configured votes - nodes: $node_votes");
283 log_info("configured votes - qdevice: $qdevice_votes");
284 log_info("current expected votes: $expected_votes");
285 log_info("current total votes: $total_votes");
286
287 log_warn("expected votes set to non-standard value '$expected_votes'.")
288 if $expected_votes != $node_votes + $qdevice_votes;
289 log_warn("total votes < expected votes: $total_votes/$expected_votes!")
290 if $total_votes < $expected_votes;
291
292 my $conf_nodelist_count = scalar(keys %$conf_nodelist);
293 my $cfs_nodelist_count = scalar(keys %$cfs_nodelist);
294 log_warn("cluster consists of less than three quorum-providing nodes!")
295 if $conf_nodelist_count < 3 && $conf_nodelist_count + $qdevice_votes < 3;
296
297 log_fail("corosync.conf ($conf_nodelist_count) and pmxcfs ($cfs_nodelist_count) don't agree about size of nodelist.")
298 if $conf_nodelist_count != $cfs_nodelist_count;
299
300 print "\nChecking nodelist entries..\n";
301 for my $cs_node (sort keys %$conf_nodelist) {
302 my $entry = $conf_nodelist->{$cs_node};
303 log_fail("$cs_node: no name entry in corosync.conf.")
304 if !defined($entry->{name});
305 log_fail("$cs_node: no nodeid configured in corosync.conf.")
306 if !defined($entry->{nodeid});
307 my $gotLinks = 0;
308 for my $link (0..7) {
309 $gotLinks++ if defined($entry->{"ring${link}_addr"});
310 }
311 log_fail("$cs_node: no ringX_addr (0 <= X <= 7) link defined in corosync.conf.") if $gotLinks <= 0;
312
313 my $verify_ring_ip = sub {
314 my $key = shift;
315 if (defined(my $ring = $entry->{$key})) {
316 my ($resolved_ip, undef) = PVE::Corosync::resolve_hostname_like_corosync($ring, $conf);
317 if (defined($resolved_ip)) {
318 if ($resolved_ip ne $ring) {
319 log_warn("$cs_node: $key '$ring' resolves to '$resolved_ip'.\n Consider replacing it with the currently resolved IP address.");
320 } else {
321 log_pass("$cs_node: $key is configured to use IP address '$ring'");
322 }
323 } else {
324 log_fail("$cs_node: unable to resolve $key '$ring' to an IP address according to Corosync's resolve strategy - cluster will potentially fail with Corosync 3.x/kronosnet!");
325 }
326 }
327 };
328 for my $link (0..7) {
329 $verify_ring_ip->("ring${link}_addr");
330 }
331 }
332
333 print "\nChecking totem settings..\n";
334 my $totem = $conf->{main}->{totem};
335 my $transport = $totem->{transport};
336 if (defined($transport)) {
337 if ($transport ne 'knet') {
338 log_fail("Corosync transport explicitly set to '$transport' instead of implicit default!");
339 } else {
340 log_pass("Corosync transport set to '$transport'.");
341 }
342 } else {
343 log_pass("Corosync transport set to implicit default.");
344 }
345
346 # TODO: are those values still up-to-date?
347 if ((!defined($totem->{secauth}) || $totem->{secauth} ne 'on') && (!defined($totem->{crypto_cipher}) || $totem->{crypto_cipher} eq 'none')) {
348 log_fail("Corosync authentication/encryption is not explicitly enabled (secauth / crypto_cipher / crypto_hash)!");
349 } else {
350 if (defined($totem->{crypto_cipher}) && $totem->{crypto_cipher} eq '3des') {
351 log_fail("Corosync encryption cipher set to '3des', no longer supported in Corosync 3.x!"); # FIXME: can be removed?
352 } else {
353 log_pass("Corosync encryption and authentication enabled.");
354 }
355 }
356
357 print "\n";
358 log_info("run 'pvecm status' to get detailed cluster status..");
359
360 print_header("CHECKING INSTALLED COROSYNC VERSION");
361 if (defined(my $corosync = $get_pkg->('corosync'))) {
362 if ($corosync->{OldVersion} =~ m/^2\./) {
363 log_fail("corosync 2.x installed, cluster-wide upgrade to 3.x needed!");
364 } elsif ($corosync->{OldVersion} =~ m/^3\./) {
365 log_pass("corosync 3.x installed.");
366 } else {
367 log_fail("unexpected corosync version installed: $corosync->{OldVersion}!");
368 }
369 }
370}
371
372sub check_ceph {
373 print_header("CHECKING HYPER-CONVERGED CEPH STATUS");
374
375 if (PVE::Ceph::Tools::check_ceph_inited(1)) {
376 log_info("hyper-converged ceph setup detected!");
377 } else {
378 log_skip("no hyper-converged ceph setup detected!");
379 return;
380 }
381
382 log_info("getting Ceph status/health information..");
383 my $ceph_status = eval { PVE::API2::Ceph->status({ node => $nodename }); };
384 my $osd_flags = eval { PVE::API2::Ceph->get_flags({ node => $nodename }); };
385 my $noout_wanted = 1;
386 my $noout = $osd_flags && $osd_flags =~ m/noout/;
387
388 if (!$ceph_status || !$ceph_status->{health}) {
389 log_fail("unable to determine Ceph status!");
390 } else {
391 my $ceph_health = $ceph_status->{health}->{status};
392 if (!$ceph_health) {
393 log_fail("unable to determine Ceph health!");
394 } elsif ($ceph_health eq 'HEALTH_OK') {
395 log_pass("Ceph health reported as 'HEALTH_OK'.");
396 } elsif ($ceph_health eq 'HEALTH_WARN' && $noout && (keys %{$ceph_status->{health}->{checks}} == 1)) {
397 log_pass("Ceph health reported as 'HEALTH_WARN' with a single failing check and 'noout' flag set.");
398 } else {
399 log_warn("Ceph health reported as '$ceph_health'.\n Use the PVE ".
400 "dashboard or 'ceph -s' to determine the specific issues and try to resolve them.");
401 }
402 }
403
404 log_info("getting Ceph OSD flags..");
405 eval {
406 if (!$osd_flags) {
407 log_fail("unable to get Ceph OSD flags!");
408 } else {
409 if ($osd_flags =~ m/recovery_deletes/ && $osd_flags =~ m/purged_snapdirs/) {
410 log_pass("all PGs have been scrubbed at least once while running Ceph Luminous."); # FIXME: remove?
411 } else {
412 log_fail("missing 'recovery_deletes' and/or 'purged_snapdirs' flag, scrub of all PGs required before upgrading to Nautilus!");
413 }
414 }
415 };
416
417 # TODO: check OSD min-required version, if to low it breaks stuff!
418
419 log_info("getting Ceph daemon versions..");
420 my $ceph_versions = eval { PVE::Ceph::Tools::get_cluster_versions(undef, 1); };
421 if (!$ceph_versions) {
422 log_fail("unable to determine Ceph daemon versions!");
423 } else {
424 my $services = [
425 { 'key' => 'mon', 'name' => 'monitor' },
426 { 'key' => 'mgr', 'name' => 'manager' },
427 { 'key' => 'mds', 'name' => 'MDS' },
428 { 'key' => 'osd', 'name' => 'OSD' },
429 ];
430
431 foreach my $service (@$services) {
432 my $name = $service->{name};
433 if (my $service_versions = $ceph_versions->{$service->{key}}) {
434 if (keys %$service_versions == 0) {
435 log_skip("no running instances detected for daemon type $name.");
436 } elsif (keys %$service_versions == 1) {
437 log_pass("single running version detected for daemon type $name.");
438 } else {
439 log_warn("multiple running versions detected for daemon type $name!");
440 }
441 } else {
442 log_skip("unable to determine versions of running Ceph $name instances.");
443 }
444 }
445
446 my $overall_versions = $ceph_versions->{overall};
447 if (!$overall_versions) {
448 log_warn("unable to determine overall Ceph daemon versions!");
449 } elsif (keys %$overall_versions == 1) {
450 log_pass("single running overall version detected for all Ceph daemon types.");
451 if ((keys %$overall_versions)[0] =~ /^ceph version 15\./) {
452 $noout_wanted = 0;
453 }
454 } else {
455 log_warn("overall version mismatch detected, check 'ceph versions' output for details!");
456 }
457 }
458
459 if ($noout) {
460 if ($noout_wanted) {
461 log_pass("'noout' flag set to prevent rebalancing during cluster-wide upgrades.");
462 } else {
463 log_warn("'noout' flag set, Ceph cluster upgrade seems finished.");
464 }
465 } elsif ($noout_wanted) {
466 log_warn("'noout' flag not set - recommended to prevent rebalancing during upgrades.");
467 }
468
469 log_info("checking Ceph config..");
470 my $conf = PVE::Cluster::cfs_read_file('ceph.conf');
471 if (%$conf) {
472 my $global = $conf->{global};
473
474 my $global_monhost = $global->{mon_host} // $global->{"mon host"} // $global->{"mon-host"};
475 if (!defined($global_monhost)) {
476 log_warn("No 'mon_host' entry found in ceph config.\n It's recommended to add mon_host with all monitor addresses (without ports) to the global section.");
477 } else {
478 log_pass("Found 'mon_host' entry.");
479 }
480
481 my $ipv6 = $global->{ms_bind_ipv6} // $global->{"ms bind ipv6"} // $global->{"ms-bind-ipv6"};
482 if ($ipv6) {
483 my $ipv4 = $global->{ms_bind_ipv4} // $global->{"ms bind ipv4"} // $global->{"ms-bind-ipv4"};
484 if ($ipv6 eq 'true' && (!defined($ipv4) || $ipv4 ne 'false')) {
485 log_warn("'ms_bind_ipv6' is enabled but 'ms_bind_ipv4' is not disabled.\n Make sure to disable 'ms_bind_ipv4' for ipv6 only clusters, or add an ipv4 network to public/cluster network.");
486 } else {
487 log_pass("'ms_bind_ipv6' is enabled and 'ms_bind_ipv4' disabled");
488 }
489 } else {
490 log_pass("'ms_bind_ipv6' not enabled");
491 }
492
493 if (defined($global->{keyring})) {
494 log_warn("[global] config section contains 'keyring' option, which will prevent services from starting with Nautilus.\n Move 'keyring' option to [client] section instead.");
495 } else {
496 log_pass("no 'keyring' option in [global] section found.");
497 }
498
499 } else {
500 log_warn("Empty ceph config found");
501 }
502
503 my $local_ceph_ver = PVE::Ceph::Tools::get_local_version(1);
504 if (defined($local_ceph_ver)) {
505 if ($local_ceph_ver == 14) {
506 my $ceph_volume_osds = PVE::Ceph::Tools::ceph_volume_list();
507 my $scanned_osds = PVE::Tools::dir_glob_regex('/etc/ceph/osd', '^.*\.json$');
508 if (-e '/var/lib/ceph/osd/' && !defined($scanned_osds) && !(keys %$ceph_volume_osds)) {
509 log_warn("local Ceph version is Nautilus, local OSDs detected, but no conversion from ceph-disk to ceph-volume done (yet).");
510 }
511 }
512 } else {
513 log_fail("unable to determine local Ceph version.");
514 }
515}
516
e522a2db
FE
517sub check_backup_retention_settings {
518 log_info("Checking backup retention settings..");
519
520 my $pass = 1;
521
522 my $node_has_retention;
523
524 my $maxfiles_msg = "parameter 'maxfiles' is deprecated with PVE 7.x and will be removed in a " .
525 "future version, use 'prune-backups' instead.";
526
527 eval {
528 my $confdesc = PVE::VZDump::Common::get_confdesc();
529
530 my $fn = "/etc/vzdump.conf";
531 my $raw = PVE::Tools::file_get_contents($fn);
532
533 my $conf_schema = { type => 'object', properties => $confdesc, };
534 my $param = PVE::JSONSchema::parse_config($conf_schema, $fn, $raw);
535
536 if (defined($param->{maxfiles})) {
537 $pass = 0;
538 log_warn("$fn - $maxfiles_msg");
539 }
540
541 $node_has_retention = defined($param->{maxfiles}) || defined($param->{'prune-backups'});
542 };
543 if (my $err = $@) {
544 $pass = 0;
545 log_warn("unable to parse node's VZDump configuration - $err");
546 }
547
548 my $storage_cfg = PVE::Storage::config();
549
550 for my $storeid (keys $storage_cfg->{ids}->%*) {
551 my $scfg = $storage_cfg->{ids}->{$storeid};
552
553 if (defined($scfg->{maxfiles})) {
554 $pass = 0;
555 log_warn("storage '$storeid' - $maxfiles_msg");
556 }
557
558 next if !$scfg->{content}->{backup};
559 next if defined($scfg->{maxfiles}) || defined($scfg->{'prune-backups'});
560 next if $node_has_retention;
561
562 log_info("storage '$storeid' - no backup retention settings defined - by default, PVE " .
563 "7.x will no longer keep only the last backup, but all backups");
564 }
565
437ade60
FG
566 eval {
567 my $vzdump_cron = PVE::Cluster::cfs_read_file('vzdump.cron');
e522a2db 568
437ade60
FG
569 # only warn once, there might be many jobs...
570 if (scalar(grep { defined($_->{maxfiles}) } $vzdump_cron->{jobs}->@*)) {
571 $pass = 0;
572 log_warn("/etc/pve/vzdump.cron - $maxfiles_msg");
573 }
574 };
575 if (my $err = $@) {
e522a2db 576 $pass = 0;
437ade60 577 log_warn("unable to parse node's VZDump configuration - $err");
e522a2db
FE
578 }
579
580 log_pass("no problems found.") if $pass;
581}
582
5df8b555
FE
583sub check_cifs_credential_location {
584 log_info("checking CIFS credential location..");
585
586 my $regex = qr/^(.*)\.cred$/;
587
588 my $found;
589
590 PVE::Tools::dir_glob_foreach('/etc/pve/priv/', $regex, sub {
591 my ($filename) = @_;
592
593 my ($basename) = $filename =~ $regex;
594
595 log_warn("CIFS credentials '/etc/pve/priv/$filename' will be moved to " .
596 "'/etc/pve/priv/storage/$basename.pw' during the update");
597
598 $found = 1;
599 });
600
601 log_pass("no CIFS credentials at outdated location found.") if !$found;
602}
603
4177a14d
TL
604sub check_misc {
605 print_header("MISCELLANEOUS CHECKS");
606 my $ssh_config = eval { PVE::Tools::file_get_contents('/root/.ssh/config') };
607 if (defined($ssh_config)) {
608 log_fail("Unsupported SSH Cipher configured for root in /root/.ssh/config: $1")
609 if $ssh_config =~ /^Ciphers .*(blowfish|arcfour|3des).*$/m;
610 } else {
611 log_skip("No SSH config file found.");
612 }
613
614 log_info("Checking common daemon services..");
615 $log_systemd_unit_state->('pveproxy.service');
616 $log_systemd_unit_state->('pvedaemon.service');
617 $log_systemd_unit_state->('pvestatd.service');
618
619 my $root_free = PVE::Tools::df('/', 10);
620 log_warn("Less than 2G free space on root file system.")
621 if defined($root_free) && $root_free->{avail} < 2*1024*1024*1024;
622
623 log_info("Checking for running guests..");
624 my $running_guests = 0;
625
626 my $vms = eval { PVE::API2::Qemu->vmlist({ node => $nodename }) };
627 log_warn("Failed to retrieve information about this node's VMs - $@") if $@;
628 $running_guests += grep { $_->{status} eq 'running' } @$vms if defined($vms);
629
630 my $cts = eval { PVE::API2::LXC->vmlist({ node => $nodename }) };
631 log_warn("Failed to retrieve information about this node's CTs - $@") if $@;
632 $running_guests += grep { $_->{status} eq 'running' } @$cts if defined($cts);
633
634 if ($running_guests > 0) {
635 log_warn("$running_guests running guest(s) detected - consider migrating or stopping them.")
636 } else {
637 log_pass("no running guest detected.")
638 }
639
640 log_info("Checking if the local node's hostname '$nodename' is resolvable..");
641 my $local_ip = eval { PVE::Network::get_ip_from_hostname($nodename) };
642 if ($@) {
643 log_warn("Failed to resolve hostname '$nodename' to IP - $@");
644 } else {
645 log_info("Checking if resolved IP is configured on local node..");
646 my $cidr = Net::IP::ip_is_ipv6($local_ip) ? "$local_ip/128" : "$local_ip/32";
647 my $configured_ips = PVE::Network::get_local_ip_from_cidr($cidr);
648 my $ip_count = scalar(@$configured_ips);
649
650 if ($ip_count <= 0) {
651 log_fail("Resolved node IP '$local_ip' not configured or active for '$nodename'");
652 } elsif ($ip_count > 1) {
653 log_warn("Resolved node IP '$local_ip' active on multiple ($ip_count) interfaces!");
654 } else {
655 log_pass("Resolved node IP '$local_ip' configured and active on single interface.");
656 }
657 }
658
659 log_info("Check node certificate's RSA key size");
660 my $certs = PVE::API2::Certificates->info({ node => $nodename });
661 my $certs_check = {
662 'rsaEncryption' => {
663 minsize => 2048,
664 name => 'RSA',
665 },
666 'id-ecPublicKey' => {
667 minsize => 224,
668 name => 'ECC',
669 },
670 };
671
672 my $certs_check_failed = 0;
673 foreach my $cert (@$certs) {
674 my ($type, $size, $fn) = $cert->@{qw(public-key-type public-key-bits filename)};
675
676 if (!defined($type) || !defined($size)) {
677 log_warn("'$fn': cannot check certificate, failed to get it's type or size!");
678 }
679
680 my $check = $certs_check->{$type};
681 if (!defined($check)) {
682 log_warn("'$fn': certificate's public key type '$type' unknown, check Debian Busters release notes");
683 next;
684 }
685
686 if ($size < $check->{minsize}) {
687 log_fail("'$fn', certificate's $check->{name} public key size is less than 2048 bit");
688 $certs_check_failed = 1;
689 } else {
690 log_pass("Certificate '$fn' passed Debian Busters security level for TLS connections ($size >= 2048)");
691 }
692 }
e522a2db
FE
693
694 check_backup_retention_settings();
5df8b555 695 check_cifs_credential_location();
4177a14d
TL
696}
697
698__PACKAGE__->register_method ({
699 name => 'checklist',
700 path => 'checklist',
701 method => 'GET',
702 description => 'Check (pre-/post-)upgrade conditions.',
703 parameters => {
704 additionalProperties => 0,
705 properties => {
706 },
707 },
708 returns => { type => 'null' },
709 code => sub {
710 my ($param) = @_;
711
712 check_pve_packages();
713 check_cluster_corosync();
714 check_ceph();
715 check_storage_health();
716 check_misc();
717
718 print_header("SUMMARY");
719
720 my $total = 0;
721 $total += $_ for values %$counters;
722
723 print "TOTAL: $total\n";
724 print colored("PASSED: $counters->{pass}\n", 'green');
725 print "SKIPPED: $counters->{skip}\n";
726 print colored("WARNINGS: $counters->{warn}\n", 'yellow');
727 print colored("FAILURES: $counters->{fail}\n", 'red');
728
729 if ($counters->{warn} > 0 || $counters->{fail} > 0) {
730 my $color = $counters->{fail} > 0 ? 'red' : 'yellow';
731 print colored("\nATTENTION: Please check the output for detailed information!\n", $color);
732 print colored("Try to solve the problems one at a time and then run this checklist tool again.\n", $color) if $counters->{fail} > 0;
733 }
734
735 return undef;
736 }});
737
738our $cmddef = [ __PACKAGE__, 'checklist', [], {}];
739
740# for now drop all unknown params and just check
741@ARGV = ();
742
7431;