]> git.proxmox.com Git - pmg-api.git/commitdiff
PMG/Postfix.pm: add command to parse qshape output
authorDietmar Maurer <dietmar@proxmox.com>
Sat, 1 Apr 2017 11:01:55 +0000 (13:01 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Sat, 1 Apr 2017 11:01:55 +0000 (13:01 +0200)
PMG/Postfix.pm

index dd6acbe124df16d3663d68d3bf58f0f147426dbe..863702158941dbe238c8d5dc6db29a476b78d473 100644 (file)
@@ -59,8 +59,8 @@ my $postfix_qenv = sub {
     return $res;
 };
 
+# Fixme: it is a bad idea to scan everything - list can be too large
 sub show_deferred_queue {
-
     my $res;
 
     my $queue = 'deferred';
@@ -86,4 +86,28 @@ sub show_deferred_queue {
     return $res;
 }
 
+sub qshape {
+    my ($queues) = @_;
+
+    open(my $fh, '-|', '/usr/sbin/qshape', $queues) || die "ERROR: unable to run qshape: $!\n";
+
+    my $line = <$fh>;
+    if (!$line || !($line =~ m/^\s+T\s+5\s+10\s+20\s+40\s+80\s+160\s+320\s+640\s+1280\s+1280\+$/)) {
+       close (CMD);
+       die "ERROR: unable to parse qshape output: - $line";
+    }
+
+    my $count = 0;
+    my $res = [];
+    while (($count++ < 10000) && (defined($line = <$fh>))) {
+       if ($line =~ m/^\s+(\S+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+)$/) {
+           push @$res, $1;
+       }
+    }
+
+    close($fh);
+
+    return $res;
+}
+
 1;