]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/Tools.pm
PVE::Tools::dump_journal: allow to filter a specific service
[pve-common.git] / src / PVE / Tools.pm
index fe35ef225e46f35d52d5c374c00e3738b8b3871b..2cd47333edf1dc043568ac0d5bcb0be782ca2828 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 use POSIX qw(EINTR EEXIST EOPNOTSUPP);
 use IO::Socket::IP;
 use warnings;
 use POSIX qw(EINTR EEXIST EOPNOTSUPP);
 use IO::Socket::IP;
-use Socket qw(AF_INET AF_INET6 AI_ALL AI_V4MAPPED);
+use Socket qw(AF_INET AF_INET6 AI_ALL AI_V4MAPPED AI_CANONNAME SOCK_DGRAM);
 use IO::Select;
 use File::Basename;
 use File::Path qw(make_path);
 use IO::Select;
 use File::Basename;
 use File::Path qw(make_path);
@@ -1081,7 +1081,7 @@ sub dump_logfile {
 }
 
 sub dump_journal {
 }
 
 sub dump_journal {
-    my ($start, $limit, $since, $until) = @_;
+    my ($start, $limit, $since, $until, $service) = @_;
 
     my $lines = [];
     my $count = 0;
 
     my $lines = [];
     my $count = 0;
@@ -1100,6 +1100,7 @@ sub dump_journal {
 
     my $cmd = ['journalctl', '-o', 'short', '--no-pager'];
 
 
     my $cmd = ['journalctl', '-o', 'short', '--no-pager'];
 
+    push @$cmd, '--unit', $service if $service;
     push @$cmd, '--since', $since if $since;
     push @$cmd, '--until', $until if $until;
     run_command($cmd, outfunc => $parser);
     push @$cmd, '--since', $since if $since;
     push @$cmd, '--until', $until if $until;
     run_command($cmd, outfunc => $parser);
@@ -1197,6 +1198,24 @@ sub get_host_address_family {
     return $res[0]->{family};
 }
 
     return $res[0]->{family};
 }
 
+# get the fully qualified domain name of a host
+# same logic as hostname(1): The FQDN is the name getaddrinfo(3) returns,
+# given a nodename as a parameter
+sub get_fqdn {
+    my ($nodename) = @_;
+
+    my $hints = {
+       flags => AI_CANONNAME,
+       socktype => SOCK_DGRAM
+    };
+
+    my ($err, @addrs) = Socket::getaddrinfo($nodename, undef, $hints);
+
+    die "getaddrinfo: $err" if $err;
+
+    return $addrs[0]->{canonname};
+}
+
 # Parses any sane kind of host, or host+port pair:
 # The port is always optional and thus may be undef.
 sub parse_host_and_port {
 # Parses any sane kind of host, or host+port pair:
 # The port is always optional and thus may be undef.
 sub parse_host_and_port {
@@ -1443,4 +1462,18 @@ sub enter_systemd_scope {
     die "systemd job never completed\n" if !$done;
 }
 
     die "systemd job never completed\n" if !$done;
 }
 
+my $salt_starter = time();
+
+sub encrypt_pw {
+    my ($pw) = @_;
+
+    $salt_starter++;
+    my $salt = substr(Digest::SHA::sha1_base64(time() + $salt_starter + $$), 0, 8);
+
+    # crypt does not want '+' in salt (see 'man crypt')
+    $salt =~ s/\+/X/g;
+
+    return crypt(encode("utf8", $pw), "\$5\$$salt\$");
+}
+
 1;
 1;