More work on status collection module
authorJamie Cameron <jcameron@webmin.com>
Sun, 4 Oct 2009 01:06:22 +0000 (18:06 -0700)
committerJamie Cameron <jcameron@webmin.com>
Sun, 4 Oct 2009 01:06:22 +0000 (18:06 -0700)
cron/cron-lib.pl
system-status/module.info
system-status/system-status-lib.pl
system-status/systeminfo.pl [new file with mode: 0755]

index 65eb85e..64904b8 100755 (executable)
@@ -1209,6 +1209,23 @@ if (!$proc && $cmd =~ /^$config_directory\/(.*\.pl)(.*)$/) {
 return $proc;
 }
 
+=head2 find_virtualmin_cron_job(command, [&jobs], [user])
+
+Returns the cron job object that runs some command (perhaps with redirection)
+
+=cut
+sub find_virtualmin_cron_job
+{
+my ($cmd, $jobs, $user) = @_;
+if (!$jobs) {
+       $jobs = [ &list_cron_jobs() ];
+       }
+$user ||= "root";
+my @rv = grep { $_->{'user'} eq $user &&
+            $_->{'command'} =~ /(^|[ \|\&;\/])\Q$cmd\E($|[ \|\&><;])/ } @$jobs;
+return wantarray ? @rv : $rv[0];
+}
+
 =head2 extract_input(command)
 
 Given a line formatted like I<command%input>, returns the command and input
index 799b1f9..cc24633 100644 (file)
@@ -2,3 +2,4 @@ desc=System Status
 longdesc=Background system status collection libraries
 hidden=1
 category=system
+depends=proc cron
index 130e5bc..514aea2 100755 (executable)
@@ -9,6 +9,8 @@
 BEGIN { push(@INC, ".."); };
 eval "use WebminCore;";
 &init_config();
+$systeminfo_cron_cmd = "$module_config_directory/systeminfo.pl";
+&foreign_require("cron", "cron-lib.pl");
 
 # collect_system_info()
 # Returns a hash reference containing system information
@@ -421,7 +423,7 @@ return @rv;
 }
 
 # setup_collectinfo_job()
-# Creates or updates the collectinfo.pl cron job, based on the schedule
+# Creates or updates the systeminfo.pl cron job, based on the schedule
 # set in the module config.
 sub setup_collectinfo_job
 {
@@ -433,7 +435,8 @@ local @mins;
 for(my $i=$offset; $i<60; $i+= $step) {
        push(@mins, $i);
        }
-local $job = &find_virtualmin_cron_job($collect_cron_cmd);
+local $job = &cron::find_cron_job($systeminfo_cron_cmd);
+
 if (!$job && $config{'collect_interval'} ne 'none') {
        # Create, and run for the first time
        $job = { 'mins' => join(',', @mins),
@@ -443,7 +446,7 @@ if (!$job && $config{'collect_interval'} ne 'none') {
                 'weekdays' => '*',
                 'user' => 'root',
                 'active' => 1,
-                'command' => $collect_cron_cmd };
+                'command' => $systeminfo_cron_cmd };
        &cron::create_cron_job($job);
        }
 elsif ($job && $config{'collect_interval'} ne 'none') {
@@ -461,7 +464,7 @@ elsif ($job && $config{'collect_interval'} eq 'none') {
        # No longer wanted, so delete
        &cron::delete_cron_job($job);
        }
-&cron::create_wrapper($collect_cron_cmd, $module_name, "collectinfo.pl");
+&cron::create_wrapper($systeminfo_cron_cmd, $module_name, "systeminfo.pl");
 }
 
 # get_current_drive_temps()
@@ -469,7 +472,7 @@ elsif ($job && $config{'collect_interval'} eq 'none') {
 sub get_current_drive_temps
 {
 local @rv;
-if (!$config{'collect_notemp'} && $virtualmin_pro &&
+if (!$config{'collect_notemp'} &&
     &foreign_installed("smart-status")) {
        &foreign_require("smart-status");
        foreach my $d (&smart_status::list_smart_disks_partitions()) {
@@ -491,7 +494,7 @@ return @rv;
 sub get_current_cpu_temps
 {
 local @rv;
-if (!$config{'collect_notemp'} && $virtualmin_pro &&
+if (!$config{'collect_notemp'} &&
     $gconfig{'os_type'} =~ /-linux$/ && &has_command("sensors")) {
        &open_execute_command(SENSORS, "sensors </dev/null 2>/dev/null", 1);
        while(<SENSORS>) {
diff --git a/system-status/systeminfo.pl b/system-status/systeminfo.pl
new file mode 100755 (executable)
index 0000000..9d8b1e7
--- /dev/null
@@ -0,0 +1,30 @@
+#!/usr/local/bin/perl
+# Collect various pieces of general system information, for display by themes
+# on their status pages. Run every 5 mins from Cron.
+
+package system_status;
+$main::no_acl_check++;
+require './system-status-lib.pl';
+$start = time();
+
+# Make sure we are not already running
+if (&test_lock($collected_info_file)) {
+       print "Already running\n";
+       exit(0);
+       }
+
+# Don't diff collected file
+$gconfig{'logfiles'} = 0;
+$gconfig{'logfullfiles'} = 0;
+$WebminCore::gconfig{'logfiles'} = 0;
+$WebminCore::gconfig{'logfullfiles'} = 0;
+$no_log_file_changes = 1;
+&lock_file($collected_info_file);
+
+$info = &collect_system_info();
+if ($info) {
+       &save_collected_info($info);
+       &add_historic_collected_info($info, $start);
+       }
+&unlock_file($collected_info_file);
+