From b7391178ffbb66033418377826cd9aea998d039f Mon Sep 17 00:00:00 2001
From: Sergey Ivanov <seriv@cs.umd.edu>
Date: Thu, 10 Aug 2023 00:36:43 -0400
Subject: [PATCH] for puppet stuck check

---
 lib/Site/PSVar.pm | 75 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100644 lib/Site/PSVar.pm

diff --git a/lib/Site/PSVar.pm b/lib/Site/PSVar.pm
new file mode 100644
index 0000000..2c253e4
--- /dev/null
+++ b/lib/Site/PSVar.pm
@@ -0,0 +1,75 @@
+package Site::PSVar;
+
+use strict;
+use warnings;
+
+use base 'Resmon::Module';
+
+use Resmon::ExtComm qw(run_command cache_command);
+
+=pod
+
+=head1 NAME
+
+Site::PSVar - get a value from the procesess table module
+
+=head1 SYNOPSIS
+
+ Site::PSVar {
+     puppet : var => etimes, aggr => max
+ }
+
+=head1 DESCRIPTION
+
+This module returns information on the state of the proceses on a running system.
+
+=head1 CONFIGURATION
+
+=over
+
+=item check_name
+
+The check name is the name of the process to pass to `ps -C` command 
+
+=item var
+
+The name of the attribute to get, like 'etimes' for elapsed time in second
+
+=item aggr
+
+The aggregate function if there are many processes with this name, now one of 2: 'max' or 'min'.
+
+=back
+
+=head1 title
+
+=head1 value
+
+=back
+
+=cut
+
+sub handler {
+    my $self = shift;
+    my $config = $self->{config}; # All configuration is in here
+    my $check_name = $self->{check_name}; # The check name is in here
+    my $var = $config->{var}; # what to look for
+    my $aggr = $config->{aggr}; # what to look for
+
+
+    my $ps_cmd = "ps -C $check_name -o $var";
+
+    my $output = run_command($ps_cmd);
+    my @values = split(/\n/, $output);
+    my $title = shift @values;
+    my @sorted = sort @values;
+    my $value = ( $aggr eq 'max' ) ? pop @sorted : shift @sorted;
+
+
+    return {
+        "title" => [$title, "s"],
+        "value" => [$value, "i"],
+    };
+};
+
+1;
-- 
GitLab