Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

hierarchical dirs from sfg and lib; EXTENDING doc

  • Loading branch information...
commit f153d48d38354bc42ab62e7e4e310febf49ffcad 1 parent 89dbbc7
@dmytro authored
View
1  .gitignore
@@ -1,3 +1,4 @@
*.yml
.*.swp
.#*
+scanner/lib/Uliska/do
View
1  parser/lib/uliska_parser/darwin/9.rb
@@ -0,0 +1 @@
+
View
144 scanner/EXTENDING.rdoc
@@ -0,0 +1,144 @@
+
+= Extending Uliska Scanner
+
+Main uliska.pl script only initializes and executes commands at the
+top level, based on OS kernel name, kernel major and minor versions.
+
+Rest is delegated to modules deeper in the +cfg+ and +lib/Uliska+
+sub-trees.
+
+Uliska can be extended to cover more OS'es -- making the name-space
+tree 'wider', or going 'deeper' in the name-space tree covering more
+specific details of the distribution or environment.
+
+== Adding new OS (going wider)
+
+At the top level of the scanner tree add files accordingly to kernel
+name and versions of UNIX system. For HP-UX 11i additional files
+should be something like:
+
+ lib/Uliska/HP-UX.pm
+ lib/Uliska/HP-UX/11.pm
+ cfg/HP-UX.cfg
+ cfg/HP-UX/11.cfg
+
+Top level files are similar to the ones describe in the following
+section.
+
+== Adding new sub-trees (going deeper)
+
+System specific scans are based on loading and executing nested list
+of commands and Perl modules. For example, for Linux sub-trees of .cfg
+and .pm files can be following:
+
+ ./cfg/Linux.cfg
+ ./cfg/Linux/Debian.cfg
+ ./cfg/Linux/Debian/5.cfg
+ ./cfg/Linux/Debian/5/4.cfg
+ ./cfg/Linux/Debian/5/5.cfg
+ ./cfg/Linux/Debian/6.cfg
+ ./cfg/Linux/RedHat/5.cfg
+ ./cfg/Linux/RedHat/5/4.cfg
+ ./cfg/Linux/RedHat/5/5.cfg
+ ./cfg/Linux/RedHat/6.cfg
+
+ ./lib/Uliska.pm
+ ./lib/Uliska/Linux.pm
+ ./lib/Uliska/Linux/Debian.pm
+ ./lib/Uliska/Linux/Debian/5.pm
+ ./lib/Uliska/Linux/Debian/5/4.pm
+ ./lib/Uliska/Linux/Debian/6.pm
+ ./lib/Uliska/Linux/RedHat.pm
+ ./lib/Uliska/Linux/RedHat/5.pm
+ ./lib/Uliska/Linux/RedHat/5/1.pm
+ ./lib/Uliska/Linux/RedHat/5/2.pm
+ ./lib/Uliska/Linux/RedHat/5/3.pm
+ ./lib/Uliska/Linux/RedHat/5/4.pm
+ ./lib/Uliska/Linux/RedHat/5/5.pm
+ ./lib/Uliska/Linux/RedHat/6.pm
+
+Modules are loaded and executed on demand. I.e. for RedHat Linux 5.4
+modules will be tried and loaded in the following order:
+
+ ./lib/Uliska/Linux.pm
+ ./lib/Uliska/Linux/RedHat.pm
+ ./lib/Uliska/Linux/RedHat/5.pm
+ ./lib/Uliska/Linux/RedHat/5/4.pm
+
+
+Accordingly lists of commands will be executed from files in the
+similar order:
+
+ ./cfg/Linux.cfg
+ ./cfg/Linux/RedHat.cfg
+ ./cfg/Linux/RedHat/5.cfg
+ ./cfg/Linux/RedHat/5/4.cfg
+
+All these files are not required to exist. In both cases (modules and
+commands) files are loaded only if they present, if not they are
+silently ignored.
+
+TODO: Add warnings for missing files for debugging.
+
+Additional granularity can be added based on DNS or NIS domain-names,
+hostnames, hardware types, etc.
+
+=== Adding your own modules
+
+This example is based on Linux.pm module. In this module we can detect
+Linux distribution name, execute commands and load modules specific
+for the distribution.
+
+- detect your distribution:
+
+ $distro = 'RedHat' if -f '/etc/redhat-release';
+ $distro = 'Debian' if -f '/etc/debian_version';
+
+- add files in cfg directory and execute commands
+
+ This will execute commands from files Uliska/Linux/RedHat.cfg or
+ Uliska/Linux/Debian.cfg:
+
+ main::executeList(main::read_commands("Linux/$distro"));
+
+- initialize and execute more nested modules
+
+ This will try to load and execute module Uliska::Linux::RedHat or
+ Uliska::Linux::Debian. Module will be executed only if load is
+ successful:
+
+ my $module = Uliska->init("Linux/$result->{distro}");
+ $module->run() if defined $module;
+
+Nesting modules can go arbitrary levels deep.
+
+
+=== Example
+
+Full text of module Linux.pm
+
+ use strict;
+
+ package Uliska::Linux;
+
+
+ sub new {
+ my $self = shift;
+ return $self;
+ }
+
+ sub run {
+ my $result = \%main::result;
+ $result->{'distro'} = &detect_distro();
+ main::executeList(main::read_commands("Linux/".$result->{distro}));
+
+ Uliska->init("Linux/$result->{distro}")->run();
+ };
+
+ sub detect_distro {
+ return 'RedHat' if -f '/etc/redhat-release';
+ return 'Debian' if -f '/etc/debian_version';
+ 'unknown';
+ }
+ 1;
+
View
0  scanner/cfg/Linux_2.cfg → scanner/cfg/Linux/2.cfg
File renamed without changes
View
5 scanner/cfg/Linux/Debian.cfg
@@ -0,0 +1,5 @@
+#
+# Commands for Debian
+#
+cat /etc/debian_version # release
+dpkg --list # packages
View
6 scanner/cfg/Linux/RedHat.cfg
@@ -0,0 +1,6 @@
+
+#
+# RedHat commands
+#
+cat /etc/redhat-release # release
+rpm -qa --queryformat="%{NAME} %{ARCH} %{VERSION} %{RELEASE} %{INSTALLTIME} %{SUMMARY}\n" # packages
View
5 scanner/cfg/RedHat.cfg
@@ -1,5 +0,0 @@
-
-#
-# RedHat commands
-#
-cat /etc/redhat-release # release
View
24 scanner/lib/Uliska.pm
@@ -81,16 +81,36 @@ returned. If module file does not exist, undef is returned.
Loaded module must provide run() function.
+=head3 Parameter
+
+=over
+
+=item $module_file
+
+Module PATH starting from $config{lib_dir}/Uliska/. Can include nested
+subdirectories.
+
+=back
+
=head3 Example
my $os = Uliska->init($result{kernel_name});
$os->run() if defined $os;
+ my $os = Uliska->init("Linux");
+
+ my $os = Uliska->init("Linux/RedHat");
+
+ my $os = Uliska->init("Linux/RedHat/5");
+
=cut
sub init {
- my ($class,$module) = (shift, shift);
- my $require_file = "$config{lib_dir}/Uliska/$module.pm";
+ my ($class,$module_file) = (shift, shift);
+
+ $module =~ s/\//::/g;
+
+ my $require_file = "$config{lib_dir}/Uliska/$module_file.pm";
$class = "Uliska::$module";
if (-f $require_file ) {
require $require_file;
View
5 scanner/lib/Uliska/Linux.pm
@@ -11,7 +11,10 @@ sub new {
sub run {
my $result = \%main::result;
$result->{'distro'} = &detect_distro();
- main::executeList(main::read_commands($result->{distro}));
+ main::executeList(main::read_commands("Linux/".$result->{distro}));
+
+ my $module = Uliska->init("Linux/$result->{distro}");
+ $module->run() if defined $module;
};
sub detect_distro {
View
31 scanner/lib/Uliska/Linux/RedHat.pm
@@ -0,0 +1,31 @@
+use strict;
+
+package Uliska::Linux::RedHat;
+
+
+sub new {
+ my $self = shift;
+ return $self;
+}
+
+sub run {
+ my $result = \%main::result;
+ $result->{'distro_version'} = &detect_version();
+
+ main::executeList(main::read_commands("Linux/RedHat/$result->{version}->{major}"));
+ main::executeList(main::read_commands("Linux/RedHat/$result->{version}->{major}/$result->{version}->{minor}"))
+
+};
+
+sub detect_version {
+ open(my $fh, '<', '/etc/redhat-release') or die $!;
+ my $rel = <$fh>;
+ if ($rel =~ /\s(\d+)\.(\d+)\s/) {
+ return {
+ major => $1,
+ minor => $2
+ };
+ }
+ undef;
+}
+1;
View
4 scanner/uliska.pl
@@ -43,8 +43,8 @@ =head1 DESCRIPTION
};
executeList(read_commands($result{kernel}{name}));
-executeList(read_commands($result{kernel}{name}."_".$result{kernel}{major}));
-executeList(read_commands($result{kernel}{name}."_".$result{kernel}{major}."_".$result{kernel}{minor}));
+executeList(read_commands($result{kernel}{name}."/".$result{kernel}{major}));
+executeList(read_commands($result{kernel}{name}."/".$result{kernel}{major}."/".$result{kernel}{minor}));
my $os = Uliska->init($result{kernel}{name});
Please sign in to comment.
Something went wrong with that request. Please try again.