Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This is an example script that will set some attributes statically and prompt the user for server unique attributes.  This script converts the nmis8/conf/Config.nmis and omk/conf/opCommon.nmis files into a perl hash.  Any attribute may be set in these configuration files with a script such as this.  This script should be run on each server from the nmis8/admin directory as it relies on NMIS perl libraries.  Notice the use of FindBin in order to find the NMIS libraries.

Code Block
#!/usr/bin/perl
use FindBin;
use lib "$FindBin::Bin/../lib";
use strict;
use func;

### This section sets domain wide NMIS properties.

my $auth_ldap_context = 'ou=example,dc=example.example,dc=com';
my $auth_ldap_server = '10.10.10.10';
my $auth_lockout_after = '3';
my $auth_method_1 = 'ldap';
my $auth_method_2 = 'htpasswd';
my $auth_method_3 = '';

my $company_logo = '/nmis8/ourLogo.jpg';

### This section sets domain wide OMK properties

### opCharts secion (OMK)
my $opcharts_gui_node_search_mode = 'prefetch';
my $opcharts_gui_refresh_time = '30';
### opConfig section (OMK)
my $opconfig_default_period = '10d';
my $opconfigd_update_delay = '1200';
my $opconfigd_update_rate = '30';
### opEvents section (OMK) 
my $opevents_dns_cache = '4800';
my $opevents_dns_retry = '200';

### This section is interactive and will prompt the user for server unique properties.

print "\nThis script will provision the NMIS/OMK server with serveral attributes.\nStatic attributes will be found at the top of the script.\nPlease open this script with a text editor and review them for accuracy.\n\nThis script will prompt the user for attrbitues that are unique to each server.\n\nPress Enter to continue.\n\n";
<>;
print "\nEnter the NMIS nmis_host value: ";
my $nmis_host = <>;
chomp $nmis_host;
print "Enter the NMIS server_name value: ";
my $server_name = <>;
chomp $server_name;
print "Enter the opEvents opevents_hostname value: ";
my $opevents_hostname = <>;
chomp $opevents_hostname;
my $nmisConf = readFiletoHash(file=>'/usr/local/nmis8/conf/Config.nmis');
my $omkConf = readFiletoHash(file=>'/usr/local/omk/conf/opCommon.nmis');
### Modify NMIS Configuration
$nmisConf->{'authentication'}{'auth_ldap_context'} = $auth_ldap_context;
$nmisConf->{'authentication'}{'auth_ldap_server'} = $auth_ldap_server;
$nmisConf->{'authentication'}{'auth_lockout_after'} = $auth_lockout_after;
$nmisConf->{'authentication'}{'auth_method_1'} = $auth_method_1;
$nmisConf->{'authentication'}{'auth_method_2'} = $auth_method_2;
$nmisConf->{'authentication'}{'auth_method_3'} = $auth_method_3;
$nmisConf->{'files'}{'company_logo'} = $company_logo;
$nmisConf->{'globals'}{'global_collect_Description'} = $global_collect_Description;
$nmisConf->{'system'}{'nmis_host'} = $nmis_host;
$nmisConf->{'system'}{'server_name'} = $server_name;
### Modify OMK Configuration
$omkConf->{'authentication'}{'auth_ldap_context'} = $auth_ldap_context;
$omkConf->{'authentication'}{'auth_ldap_server'} = $auth_ldap_server;
$omkConf->{'authentication'}{'auth_lockout_after'} = $auth_lockout_after;
$omkConf->{'authentication'}{'auth_method_1'} = $auth_method_1;
$omkConf->{'authentication'}{'auth_method_3'} = $auth_method_3;
$omkConf->{'opcharts'}{'opcharts_gui_node_search_mode'} = $opcharts_gui_node_search_mode;
$omkConf->{'opcharts'}{'opcharts_gui_refresh_time'} = $opcharts_gui_refresh_time;
$omkConf->{'opconfig'}{'opconfig_default_period'} = $opconfig_default_period;
$omkConf->{'opconfig'}{'opconfigd_update_delay'} = $opconfigd_update_delay;
$omkConf->{'opconfig'}{'opconfigd_update_rate'} = $opconfigd_update_rate;
$omkConf->{'opevents'}{'opevents_hostname'} = $opevents_hostname;
$omkConf->{'opevents'}{'opevents_dns_cache'} = $opevents_dns_cache;
$omkConf->{'opevents'}{'opevents_dns_retry'} = $opevents_dns_retry;
$omkConf->{'opevents'}{'opevents_import_node_interfaces'} = $opevents_import_node_interfaces;
#writeHashtoFile(file=>'/usr/local/nmis8/conf/Config.nmis', data=>$nmisConf);
writeHashtoFile(file=>'/tmp/Config.nmis', data=>$nmisConf);
#writeHashtoFile(file=>'/usr/local/omk/conf/opCommon.nmis', data=>$omkConf);
writeHashtoFile(file=>'/tmp/opCommon.nmis', data=>$omkConf);
print "\nConfiguration update is complete!\n";
print "\nIn order for the new OMK attributes to take affect the associated\n";
print "Daemons should be restarted.  Wold you like to restart the deamons now?\n";
print "yes or no?: ";
my $choice = <>;
chomp $choice;
if ( $choice eq "yes" ) {
    system("service opeventsd restart");
    system("service opconfigd restart");
    system("service omkd restart");
}
else {
    print "\nThe following Daemons will need to be restarted before these changes will take affect.\n";
    print "\t- opeventsd\n\t- opconfigd\n\t- omkd\n";
}
print "\nThis action is complete.\n\n";