Modified:
/trunk/server/lib/SysFink/Server.pm
/trunk/server/sysfink.pl
/trunk/server/utils/scan-loop.sh
/trunk/server/utils/test-new.sh
=======================================
--- /trunk/server/lib/SysFink/Server.pm Wed Jan 13 13:47:18 2010
+++ /trunk/server/lib/SysFink/Server.pm Thu Jan 14 14:12:36 2010
@@ -130,6 +130,13 @@
'type' => 'self',
},
+ 'audit' => {
+ 'connect_to_db' => 1,
+ 'validate_host_name_if_given' => 1,
+ 'get_who' => { mandatory => 1, },
+ 'type' => 'self',
+ },
+
}; # $all_cmd_confs end
# Options used somewhere below:
@@ -843,7 +850,7 @@
my $machine_id = $self->{host_conf}->{machine_id};
my $mconf_sec_id = $self->{host_conf}->{mconf_sec_id};
- # Insert scan row.
+ # Insert scan row. Before transaction start.
my $scan_row = $schema->resultset('scan')->create({
mconf_sec_id => $mconf_sec_id,
start_time => DateTime->now,
@@ -1088,17 +1095,37 @@
}
-=head2 diff_cmd
-
-Run diff command.
+=head2 get_attr_str
+
+Run string representation for given value of given attribute type.
=cut
-sub diff_cmd {
- my ( $self, $opt ) = @_;
-
- my $ver = $self->{ver};
- my $schema = $self->{schema};
+sub get_attr_str {
+ my ( $self, $attr, $value ) = @_;
+
+ return 'undef' unless defined $value;
+
+ if ( $attr eq 'mode' ) {
+ return $self->mode_to_lsmode( $value );
+ }
+
+ if ( $attr eq 'mtime' ) {
+ return DateTime->from_epoch( epoch => $value )->datetime;;
+ }
+
+ return $value;
+}
+
+
+=head2 check_and_load_host_and_section
+
+Check and load machine_id and mconf_sec_id from given --host and --section.
+
+=cut
+
+sub check_and_load_host_and_section {
+ my ( $self, $opt ) = @_;
# Check params.
my $host = $opt->{host};
@@ -1120,6 +1147,25 @@
$mconf_sec_id = $mconf_sec_data->[0];
}
}
+
+ return ( 1, $machine_id, $mconf_sec_id );
+}
+
+
+=head2 diff_cmd
+
+Run diff command.
+
+=cut
+
+sub diff_cmd {
+ my ( $self, $opt ) = @_;
+
+ my ( $ret_code, $machine_id, $mconf_sec_id ) =
$self->check_and_load_host_and_section( $opt );
+ return 0 unless $ret_code;
+
+ my $ver = $self->{ver};
+ my $schema = $self->{schema};
my $attrs_conf = get_item_attrs();
@@ -1131,7 +1177,8 @@
sd.found
si.sc_mitem_id
psd.found
- machine.name
+ machine.name
+ aid.aud_status_id
/ ];
my $idata_items = [];
@@ -1172,11 +1219,15 @@
my $data = $schema->storage->dbh_do(
sub {
- my ( $storage, $dbh, $cols_str, $data ) = @_;
+ my ( $storage, $dbh, $cols_str, $in_params ) = @_;
return $dbh->selectall_arrayref("
select $cols_str
from sc_idata sd
left join sc_idata psd on psd.newer_id = sd.sc_idata_id
+ left join aud_idata aid on (
+ aid.sc_idata_id = sd.sc_idata_id
+ and aid.newer_id is null
+ )
inner join sc_mitem si on si.sc_mitem_id = sd.sc_mitem_id
inner join path on path.path_id = si.path_id
inner join scan on scan.scan_id = sd.scan_id
@@ -1187,9 +1238,12 @@
and ( ? is null or scan.mconf_sec_id = ? )
and ( ? is null or machine.machine_id = ? )
and machine.active = 1
+ and ( aid.aud_idata_id is null
+ or ( aid.aud_status_id != 1 and
aid.aud_status_id != 2 )
+ )
order by machine.machine_id, path.path
",
- {}, @$data
+ {}, @$in_params
);
},
$cols_sql_str,
@@ -1210,18 +1264,26 @@
# path
my $path_str = " " . $row->[ $name_to_pos->{path_path} ];
$path_str .= " (sc_mitem=" . $row->[
$name_to_pos->{si_sc_mitem_id} ] . ")" if $self->{ver} >= 4;
- $path_str .=":";
-
- # diff init
+
+ # diff_str init
my $diff_str = '';
if ( ! $row->[ $name_to_pos->{'psd_found'} ] ) {
- $diff_str .= " added\n";
+ $path_str .= " - added";
+ foreach my $attr ( keys %$attrs_conf ) {
+ my $new = $row->[ $name_to_pos->{'sd_'.$attr} ];
+ $diff_str .= " $attr: " . $self->get_attr_str($attr,
$new) . "\n";
+ }
} elsif ( ! $row->[ $name_to_pos->{'sd_found'} ] ) {
- $diff_str .= " deleted\n";
+ $path_str .= " - deleted";
+ foreach my $attr ( keys %$attrs_conf ) {
+ my $old = $row->[ $name_to_pos->{'psd_'.$attr} ];
+ $diff_str .= " $attr: " . $self->get_attr_str($attr,
$old) . "\n";
+ }
} else {
+ $path_str .= " - changed";
# attrs changes
foreach my $attr ( keys %$attrs_conf ) {
@@ -1233,23 +1295,26 @@
if ( (not defined $new) && (not defined $old) ) {
# ok
} elsif ( not defined $new ) {
- $diff_str .= " $attr: $old -> undef\n";
+ $diff_str .= " $attr: ";
+ $diff_str .= $self->get_attr_str($attr, $old);
+ $diff_str .= " -> undef\n";
} else {
- $diff_str .= " $attr: undef -> $new\n";
+ $diff_str .= " $attr: undef -> ";
+ $diff_str .= $self->get_attr_str($attr, $new);
+ $diff_str .= "\n";
}
} elsif ( ($is_number && $new != $old) || (!$is_number &&
$new ne $old) ) {
- if ( $attr eq 'mode' ) {
- my $old_mode_str = $self->mode_to_lsmode( $old );
- my $new_mode_str = $self->mode_to_lsmode( $new );
- $diff_str .= " $attr: $old_mode_str ->
$new_mode_str\n";
- } else {
- $diff_str .= " $attr: $old -> $new\n";
- }
+ $diff_str .= " $attr: ";
+ $diff_str .= $self->get_attr_str($attr, $old);
+ $diff_str .= " -> ";
+ $diff_str .= $self->get_attr_str($attr, $new);
+ $diff_str .= "\n";
}
} # foreach
}
+ $path_str .= " (id:" . $row->[ $name_to_pos->{sd_sc_idata_id}
] . ")";
if ( $diff_str ) {
if ( defined $machine_str ) {
print $machine_str . "\n";
@@ -1261,9 +1326,92 @@
}
print $diff_str;
$diff_str = undef;
- }
-
- }
+
+ if ( defined $row->[ $name_to_pos->{aid_aud_status_id} ] ) {
+ print " last audit status: " . $row->[
$name_to_pos->{aid_aud_status_id} ] . "\n";
+ }
+ print "\n";
+ }
+ }
+
+ return 1;
+}
+
+
+=head2 audit_cmd
+
+Run audit command.
+
+=cut
+
+sub audit_cmd {
+ my ( $self, $opt ) = @_;
+
+ my ( $ret_code, $machine_id, $mconf_sec_id ) =
$self->check_and_load_host_and_section( $opt );
+ return 0 unless $ret_code;
+
+ my $aud_status_id = 1;
+
+ my $ver = $self->{ver};
+ my $schema = $self->{schema};
+
+ $schema->storage->txn_begin;
+
+ my $msg = undef;
+
+ # Insert aud info.
+ my $aud_row = $schema->resultset('aud')->create({
+ date => DateTime->now,
+ user_id => $self->{user_id},
+ msg => $msg,
+ });
+ my $aud_id = $aud_row->aud_id;
+
+ my $cols_sql_str = "sd.sc_idata_id";
+ my $data = $schema->storage->dbh_do(
+ sub {
+ my ( $storage, $dbh, $cols_str, $in_params ) = @_;
+ return $dbh->selectall_arrayref("
+ select $cols_str
+ from sc_idata sd
+ inner join sc_mitem si on si.sc_mitem_id = sd.sc_mitem_id
+ inner join path on path.path_id = si.path_id
+ inner join scan on scan.scan_id = sd.scan_id
+ inner join mconf_sec mcs on mcs.mconf_sec_id =
scan.mconf_sec_id
+ inner join mconf mc on mc.mconf_id = mcs.mconf_id
+ inner join machine on machine.machine_id = mc.machine_id
+ where sd.newer_id is null
+ and ( ? is null or scan.mconf_sec_id = ? )
+ and ( ? is null or machine.machine_id = ? )
+ and machine.active = 1
+ and not exists (
+ select 1
+ from aud_idata aid
+ where aid.sc_idata_id = sd.sc_idata_id
+ and aid.newer_id is null
+ )
+ order by machine.machine_id, path.path
+ ",
+ {}, @$in_params
+ );
+ },
+ $cols_sql_str,
+ [ $mconf_sec_id, $mconf_sec_id, $machine_id, $machine_id ],
+
+ );
+
+ foreach my $row ( @$data ) {
+ my $sc_idata_id = $row->[0];
+ my $aud_idata_row = $schema->resultset('aud_idata')->create({
+ aud_id => $aud_id,
+ sc_idata_id => $sc_idata_id,
+ aud_status_id => $aud_status_id,
+ newer_id => undef,
+ });
+ print "sc_idata_id $sc_idata_id audit status sets to
$aud_status_id\n" if $ver >= 4;
+ }
+
+ $schema->storage->txn_commit;
return 1;
}
=======================================
--- /trunk/server/sysfink.pl Sat Jan 9 16:29:43 2010
+++ /trunk/server/sysfink.pl Thu Jan 14 14:12:36 2010
@@ -87,77 +87,83 @@
--cmd=test_hostname
For testing purpose. Run 'hostname' command on client and compare
it to --host.
Return nothing (on success) or error message.
- Also required --host.
- Also require --ssh_user if --no_db given.
+ Also required --host=?.
+ Also require --ssh_user=? if --no_db given.
+
+ --host=? ... Full hostname of client for SSH connect.
+
+ --section=? ... Configuration section name to use.
+
+ --no_db
+ Do not connect to DB. Parameters like ssh_user or host_dist_type
are required
+ for some commands.
+
+ --ssh_user=? ... User name for SSH connect.
--cmd=check_client_dir
Run 'ls -l' command on client and validate output.
Return nothing (on success) or error message.
- Also required --host.
- Also require --ssh_user if --no_db given.
+ Also required --host=?.
+ Also require --ssh_user=? if --no_db given.
--cmd=remove_client_dir
Remove SysFink directory on client. Call 'check_client_dir' to
ensure that anything else will be removed.
Return nothing (on success) or error message.
- Also required --host.
- Also require --ssh_user if --no_db given.
+ Also required --host=?.
+ Also require --ssh_user=? if --no_db given.
--cmd=renew_client_dir
Remove old and put new client source code (scripts and libraries)
on client machine. Call 'remove_client_dir'
(and 'check_client_dir') and then put new code.
Return nothing (on success) or error message.
- Also required --host.
- Also require --ssh_user and --host_dist_type if --no_db given.
+ Also required --host=?.
+ Also require --ssh_user=? and --host_dist_type=? if --no_db given.
+
+ --host_dist_type=? ... Distribution type e.g. irix-bin-64b,
linux-perl-md5, ...
--cmd=test_noop_rpc
Try to run 'noop' test command on client shell over RPC. You
should run 'renew_client_dir' cmd to transfer
RPC source code to client first.
Return nothing (on success) or error message.
- Also required --host.
- Also require --ssh_user if --no_db given.
+ Also required --host=?.
+ Also require --ssh_user=? if --no_db given.
--cmd=test_three_parts_rpc
Try to run 'tree_parts' test command on client shell over RPC. You
should run 'renew_client_dir' cmd to transfer
RPC source code to client first.
Return nothing (on success) or error message.
- Also required --host.
- Also require --ssh_user if --no_db given.
+ Also required --host=?.
+ Also require --ssh_user=? if --no_db given.
--cmd=mconf_to_db
Load machine config files to DB.
Optional --mconf_path=? to specify base path where are machine
config files located.
+ Optional --who=?.
+
+ --who=?
+ User login to find user_id. Default is determined by terminal
user/login info compared
+ with 'who' attribute in DB.
--cmd=scan_test
Run scan_test command on given host. Load config from database,
run scan comand in debug mode (online debug
output) and do not change anything inside DB.
Return nothing (on success) or error message.
- Also required --host.
+ Also required --host=?.
--cmd=scan
Run scan on given host. Load config from database and save results
there.
Return nothing (on success) or error message.
- Also required --host.
+ Also required --host=?.
--cmd=diff
- Show diff for given host.
- Also required --host.
-
- --host=? ... Full hostname of client for SSH connect.
-
- --section=? ... Configuration section name to use.
-
- --who=?
- User login to find user_id. Default is determined by terminal
user/login info compared
- with 'who' attribute in DB.
-
- --no_db
- Do not connect to DB. Parameters like ssh_user or host_dist_type
are required
- for some commands.
-
- --ssh_user=? ... User name for SSH connect.
-
- --host_dist_type=? ... Distribution type e.g. irix-bin-64b,
linux-perl-md5, ...
-
+ Show diff for given host or given host and section.
+ Optional --host=?, --section=?.
+
+ --cmd=audit
+ Set audit for all hosts, given host, given host and section or
given list of sc_idata_id.
+ Mandatory --who=? if not found automaticaly from tty login.
+ Optional --host=?, --section=?.
+
=head1 DESCRIPTION
B<This program> run SysFink server command.
=======================================
--- /trunk/server/utils/scan-loop.sh Wed Jan 13 13:59:42 2010
+++ /trunk/server/utils/scan-loop.sh Thu Jan 14 14:12:36 2010
@@ -1,10 +1,12 @@
#!/bin/bash
-if [ -z "$2" ]; then
+if [ -z "$3" ]; then
echo "Usage:"
- echo " utils/scan-loop.sh hostname verbosity_level [sleep_time]"
+ echo " utils/scan-loop.sh hostname verbosity_level do_full_scan
[sleep_time]"
echo ""
- echo " nice -n 10 utils/scan-loop.sh tapir1 3 | tee
temp/scan-loop-out.txt"
+ echo " utils/scan-loop.sh tapir1 3 0 30"
+ echo ""
+ echo " nice -n 10 utils/scan-loop.sh tapir1 3 1 1800 | tee
temp/scan-loop-out.txt"
echo ""
exit
fi
@@ -12,19 +14,25 @@
# mandatory
HOST="$1"
VER="$2"
+DO_FULL_SCAN="$3"
# optional
-SLEEP_TIME="$3"
+SLEEP_TIME="$4"
if [ -z "$SLEEP_TIME" ]; then
- SLEEP_TIME=30
+ SLEEP_TIME=1800
fi
-
-for ((i=1;1;i++)); do
- echo "Run number: " $i
- date
- echo ""
-
+echo "Parameters:"
+echo " host: $HOST"
+echo " verbosity: $VER"
+echo " do full scan: $DO_FULL_SCAN"
+echo " sleep time: $SLEEP_TIME"
+echo ""
+echo ""
+
+for ((inum=1;1;inum++)); do
+ echo "Run number $inum"
+
echo "Running --cmd=mconf_to_db:"
perl sysfink.pl --cmd=mconf_to_db
echo ""
@@ -33,26 +41,58 @@
perl sysfink.pl --host=$HOST --cmd=renew_client_dir --ver=$VER
echo ""
- echo "Running $HOST 'tmpscan':"
- perl sysfink.pl --host=$HOST --cmd=scan --section=tmpscan --ver=$VER
- echo ""
-
- echo "Running 'diff' on 'tmpscan' section:"
- perl sysfink.pl --cmd=diff --host=$HOST --section=tmpscan --ver=$VER
- echo ""
-
- echo "Running $HOST 'fastscan':"
- perl sysfink.pl --host=$HOST --cmd=scan --section=fastscan --ver=$VER
- echo ""
-
- echo "Running 'diff' on 'fastscan' section:"
- perl sysfink.pl --cmd=diff --host=$HOST --section=fastscan --ver=$VER
- echo ""
-
- echo "Sleeping $SLEEP_TIME s ..."
- sleep $SLEEP_TIME
-
- echo ""
- echo ""
+ for ((jnum=1;jnum<=24;jnum++)); do
+ echo -n "Fast run number $jnum - "
+ date
+ echo ""
+
+ echo "Running 'tmpscan' on $HOST:"
+ perl sysfink.pl --host=$HOST --cmd=scan --section=tmpscan
--ver=$VER
+ echo ""
+
+ echo "Running 'diff' for section 'tmpscan' and host $HOST:"
+ perl sysfink.pl --cmd=diff --host=$HOST --section=tmpscan
--ver=$VER
+ echo ""
+
+ echo "Running 'audit' for section 'tmpscan' and host $HOST:"
+ perl sysfink.pl --cmd=audit --host=$HOST --section=tmpscan
--ver=$VER
+ echo ""
+
+
+ echo "Running 'fastscan' on $HOST:"
+ perl sysfink.pl --host=$HOST --cmd=scan --section=fastscan
--ver=$VER
+ echo ""
+
+ echo "Running 'diff' for section 'fastscan' and host $HOST:"
+ perl sysfink.pl --cmd=diff --host=$HOST --section=fastscan
--ver=$VER
+ echo ""
+
+ echo "Running 'audit' for section 'fastscan' and host $HOST:"
+ perl sysfink.pl --cmd=audit --host=$HOST --section=fastscan
--ver=$VER
+ echo ""
+
+ echo "Sleeping $SLEEP_TIME s ..."
+ sleep $SLEEP_TIME
+
+ echo ""
+ echo ""
+ done
+
+
+ if [ "$DO_FULL_SCAN" = "1" ]; then
+ echo "Running full scan on $HOST:"
+ perl sysfink.pl --host=$HOST --cmd=scan --ver=$VER
+ echo ""
+
+ echo "Running full 'diff' for host $HOST:"
+ perl sysfink.pl --cmd=diff --host=$HOST --ver=$VER
+ echo ""
+
+ echo "Running full 'audit' for host $HOST:"
+ perl sysfink.pl --cmd=audit --host=$HOST --section=fastscan
--ver=$VER
+ echo ""
+ echo ""
+ fi
+
done
=======================================
--- /trunk/server/utils/test-new.sh Wed Jan 13 13:59:42 2010
+++ /trunk/server/utils/test-new.sh Thu Jan 14 14:12:36 2010
@@ -181,6 +181,12 @@
echo "Running utils/all-sql.sh $CLEAR"
./utils/all-sql.sh $CLEAR
echo ""
+
+ # create sysfink.pl doc
+ if [ "$CLEAR" = "2" ]; then
+ echo "Generating new help to temp/doc/help.txt"
+ perl sysfink.pl --help > temp/doc/help.txt
+ fi
if [ "$DB_TYPE" = "sqlite" ]; then
echo "Executing temp/schema-raw-create-sqlite.sql (perl
utils/db-run-sqlscript.pl):"
@@ -238,9 +244,15 @@
# test type: dev
if [ $TEST_TYPE = "dev" ]; then
- echo "Running 'perl ... --cmd=scan --section=testscan'."
- perl sysfink.pl --host=$HOST --cmd=scan --section=testscan --ver=$VER
- echo "Done."
+ echo "Running 'perl ... --cmd=scan --section=testscan'." \
+ && perl sysfink.pl --host=$HOST --cmd=scan --section=testscan
--ver=$VER \
+ && echo "Running 'perl ... --cmd=diff --section=testscan | tail -n
15'." \
+ && perl sysfink.pl --host=$HOST --cmd=diff --section=testscan
--ver=$VER | tail -n 15 \
+ && echo "Running 'perl ... --cmd=audit --section=testscan'." \
+ && perl sysfink.pl --host=$HOST --cmd=audit --section=testscan
--ver=$VER \
+ && echo "Running 'perl ... --cmd=diff --section=testscan' after
audit." \
+ && perl sysfink.pl --host=$HOST --cmd=diff --section=testscan
--ver=$VER \
+ && echo "Done."
export SYSFINK_DEVEL=0