OSSP CVS Repository

ossp - Check-in [3540]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 3540
Date: 2003-Sep-02 17:37:26 (local)
2003-Sep-02 15:37:26 (UTC)
User:rse
Branch:
Comment: use new MIB SEQUENCE support in framework to provide initial OpenPKG RPM instance information
Tickets:
Inspections:
Files:
ossp-pkg/snmpdx/snmpdx.d/swOp.pm      1.2 -> 1.3     61 inserted, 9 deleted

ossp-pkg/snmpdx/snmpdx.d/swOp.pm 1.2 -> 1.3

--- swOp.pm      2003/09/01 15:36:57     1.2
+++ swOp.pm      2003/09/02 15:37:26     1.3
@@ -30,20 +30,72 @@
 
 sub oids ($) {
     my ($self) = @_;
-    return []; # FIXME
-    my $oids = [];
-    push(@{$oids}, @{$self->{-ctx}->{-mib}->oids("*.snmpdx.host.software.swOp.swOpVersion")});
-    foreach my $oid (@{$self->{-ctx}->{-mib}->oids("*.snmpdx.host.software.swOp.swOpPkg.*")}) {
-        push(@{$oids}, $oid.".1");
-        push(@{$oids}, $oid.".2");
-        push(@{$oids}, $oid.".3");
-    }
-    return $oids;
+    return $self->{-ctx}->{-mib}->oids("*.snmpdx.host.software.swOp.*");
 }
 
 sub probe ($$) {
     my ($self, $obj) = @_;
 
+    #   query details via rpm(1)
+    my $out = $self->{-ctx}->{-sys}->run(
+        "xrpm -qa --qf '[%{NAME} %{VERSION} %{RELEASE} %{BUILDTIME} %{INSTALLTIME}\\n]'", "10m");
+
+    #   parse details into internal structure
+    my $pkg = [];
+    foreach my $entry (sort(split(/\n/, $out->{-stdout}))) {
+        my ($p_n, $p_v, $p_r, $p_bt, $p_it) = split(/\s+/, $entry);
+        my $p = { -name => $p_n, -version => $p_v, -release => $p_r, -built => $p_bt, -installed => $p_it };
+        push(@{$pkg}, $p);
+    }
+
+    #   provide result
+    $self->{-ctx}->{-log}->printf(4, "name=%s", $obj->{-name});
+    if ($obj->{-name} =~ m|\.swOpVersion$|) {
+        #   OpenPKG instance *main* version
+        my %release = ();
+        foreach my $p (@{$pkg}) {
+            my $r = $p->{-release};
+            $r =~ s|^(\d+\.d+)\.\d+$|$1|s;
+            $r =~ s|^\d{8}$|CURRENT|s;
+            $release{$r}++;
+        }
+        my $release = (reverse sort { $release{$a} <=> $release{$b} } keys(%release))[0];
+        $obj->{-value} = "OpenPKG-$release";
+    }
+    elsif ($obj->{-name} =~ m|\.swOpPkgENTRY\.([^.]+)\.(\d+)$|) {
+        #   OpenPKG package list
+        my $col = $1;
+        my $row = ($2 > 0 ? $2 - 1 : 0);
+        $self->{-ctx}->{-log}->printf(4, "col=%s row=%s", $col, $row);
+        if (defined($pkg->[$row])) {
+            if ($col eq 'swOpPkgIndex') {
+                $obj->{-value} = $row;
+            }
+            elsif ($col eq 'swOpPkgName') {
+                $obj->{-value} = $pkg->[$row]->{-name};
+            }
+            elsif ($col eq 'swOpPkgVersion') {
+                $obj->{-value} = $pkg->[$row]->{-version};
+            }
+            elsif ($col eq 'swOpPkgRelease') {
+                $obj->{-value} = $pkg->[$row]->{-release};
+            }
+            elsif ($col eq 'swOpPkgBuilt') {
+                local ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
+                    localtime($pkg->[$row]->{-built});
+                $obj->{-value} = $self->{-ctx}->{-enc}->dat_encode(
+                    sprintf("%04d-%02d-%02d %02d:%02d:%02d",
+                        $year+1900, $mon+1, $mday, $hour, $min, $sec));
+            }
+            elsif ($col eq 'swOpPkgInstalled') {
+                local ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
+                    localtime($pkg->[$row]->{-installed});
+                $obj->{-value} = $self->{-ctx}->{-enc}->dat_encode(
+                    sprintf("%04d-%02d-%02d %02d:%02d:%02d",
+                        $year+1900, $mon+1, $mday, $hour, $min, $sec));
+            }
+        }
+    }
     return;
 }
 

CVSTrac 2.0.1