-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckconfig.pl
730 lines (656 loc) · 31.5 KB
/
checkconfig.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
use strict;
use warnings;
# ************************************************* #
# Chargement des librairies !
# ************************************************* #
use lib "X:/Nimsoft/perllib";
use Nimbus::API;
use Nimbus::CFG;
use Nimbus::PDS;
# ************************************************* #
# Chargement des packages !
# ************************************************* #
use Nimprobe::struct;
use Nimprobe::hub;
use Nimprobe::robot;
use Nimprobe::probe;
use Libs::Tools;
use Cwd;
use Time::HiRes qw( time );
use DBI;
use Term::ANSIColor qw(:constants);
use File::Copy;
# ************************************************* #
# Global vars
# ************************************************* #
my $LOG = 1;
my $GBL_Time_ScriptExecutionTime = time();
my $GBL_Time_ExecutionTimeStart = Libs::Tools::LogTime();
my $GBL_STR_ProbeName = "checkconfig";
my $GBL_STR_ProveVersion = "2.8";
my $GBL_STR_Directory = getcwd;
my $GBL_STR_RemoteHUB = "hub";
my $GBL_STR_Time_Format = "%.2f";
my $GBL_INT_FailCount = 0;
my $DB;
my $CFG = Nimbus::CFG->new("$GBL_STR_ProbeName.cfg");
my %GBL_Hash_Hubs = ();
{
my @Temp_Hubs = split(",",$CFG->{"monitoring"}->{"hubs_list"});
foreach(@Temp_Hubs) {
$GBL_Hash_Hubs{$_} = 1;
}
}
my %Excluded_Robots;
{
my @Temp_Excluded_Robots = split(",",$CFG->{"monitoring"}->{"excluded_robots"});
foreach(@Temp_Excluded_Robots) {
$Excluded_Robots{$_} = 1;
}
}
my $domain = $CFG->{"setup"}->{"domain"};
my @MonitoredProbes = split(",",$CFG->{"monitoring"}->{"monitored_probes"});
my $GetRobotConfiguration = $CFG->{"monitoring"}->{"get_probes_configuration"};
my $hubs_restrict = $CFG->{"monitoring"}->{"hubs_restrict"};
my $conf_commit = $CFG->{"monitoring"}->{"conf_commit"};
my $get_probes_log = $CFG->{"monitoring"}->{"get_probes_log"};
my $get_packages = $CFG->{"monitoring"}->{"get_packages"} || 0;
my $get_processes = $CFG->{"monitoring"}->{"get_processes"} || 0;
my $robot_secondcheck = $CFG->{"monitoring"}->{"robots_secondcheck"};
# Load WITH -F param !
my $RobotTXT = 0;
my %RobotsHash_TXT = ();
# ************************************************* #
# Create local directory for the probes
# ************************************************* #
Libs::Tools::createDir("Output;Output/$GBL_Time_ExecutionTimeStart");
# ************************************************* #
# Création et configuration de la probe !
# ************************************************* #
my $NMS_Probe;
$NMS_Probe = new Nimprobe::struct($GBL_STR_ProbeName,$GBL_STR_ProveVersion);
$NMS_Probe->start();
{
sub breakApplication { # Ctrl-C key in console-mode for breaking script !
print "\n\n!!! CTRL-C BREAKING CONSOLE !!!\n\n";
$DB->commit;
$DB->disconnect;
exit(1);
}
$SIG{INT} = \&breakApplication;
}
# ************************************************* #
# Requête SQL cross platform
# ************************************************* #
my %RequeteSQL = (
"SQLite" => {
createHUB => "CREATE TABLE IF NOT EXISTS hubs_list (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(255) NOT NULL,
domain TEXT NOT NULL,
origin TEXT,
ip TEXT NOT NULL,
versions VARCHAR(255),
tunnel VARCHAR(10) NOT NULL,
getrobots_success TINYINT,
getrobots_time INTEGER,
getallrobots_time INTEGER
)",
createROBOT => "CREATE TABLE IF NOT EXISTS robots_list (
id INTEGER PRIMARY KEY AUTOINCREMENT,
hubid INTEGER NOT NULL,
status TINYINT NOT NULL,
os_major TEXT,
os_user1 TEXT,
os_user2 TEXT,
os_minor TEXT,
os_description TEXT,
name VARCHAR(255) NOT NULL,
ip TEXT NOT NULL,
origin TEXT NOT NULL,
versions VARCHAR(255),
probeslist_success TINYINT,
probeslist_responsetime INTEGER,
packages_success TINYINT,
FOREIGN KEY(hubid) REFERENCES hubs_list(id)
)",
createPROBE => "CREATE TABLE IF NOT EXISTS probes_list (
id INTEGER PRIMARY KEY AUTOINCREMENT,
robotid INTEGER NOT NULL,
name TEXT NOT NULL,
active TINYINT NOT NULL,
versions VARCHAR(255),
build INTEGER,
process_state TEXT,
getconfig_success TINYINT,
getconfig_responsetime INTEGER,
FOREIGN KEY(robotid) REFERENCES robots_list(id)
)",
createPKG => "CREATE TABLE IF NOT EXISTS packages_list (
id INTEGER PRIMARY KEY AUTOINCREMENT,
robotid INTEGER NOT NULL,
name VARCHAR(255) NOT NULL,
description TEXT,
version VARCHAR(255),
build VARCHAR(255),
date DATE,
install_date DATE,
FOREIGN KEY(robotid) REFERENCES robots_list(id)
)",
createPROCESSES => "CREATE TABLE IF NOT EXISTS processes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
robotid INTEGER NOT NULL,
executable VARCHAR(255),
command_line VARCHAR(255),
binary_path VARCHAR(255),
user VARCHAR(255),
short_executable VARCHAR(255),
FOREIGN KEY(robotid) REFERENCES robots_list(id)
)",
createMISSING => "CREATE TABLE IF NOT EXISTS missing_probes (
robotid INTEGER NOT NULL,
name TEXT NOT NULL,
FOREIGN KEY(robotid) REFERENCES robots_list(id)
)",
createCONF => "CREATE TABLE IF NOT EXISTS probes_config (
id INTEGER PRIMARY KEY AUTOINCREMENT,
probeid INTEGER NOT NULL,
probe TEXT NOT NULL,
profile TEXT NOT NULL,
active VARCHAR(255),
FOREIGN KEY(probeid) REFERENCES probes_list(id)
)",
dropROBOT => 'DROP TABLE IF EXISTS robots_list;',
dropPROCESSES => 'DROP TABLE IF EXISTS processes;',
dropPROBE => 'DROP TABLE IF EXISTS probes_list;',
dropHUB => 'DROP TABLE IF EXISTS hubs_list;',
dropCONF => 'DROP TABLE IF EXISTS probes_config;',
dropMISSING => 'DROP TABLE IF EXISTS missing_probes;',
dropPKG => 'DROP TABLE IF EXISTS packages_list;'
}
);
$RequeteSQL{"MySQL"} = $RequeteSQL{"SQLite"};
my $DB_File = "checkconfig.db";
if(-e $DB_File) {
print "Unlink database file!\n";
unlink($DB_File);
}
# ************************************************* #
# Connexion et Hydratation
# ************************************************* #
my $GBL_STR_DB_Type = $CFG->{"database"}->{"type"};
my $GBL_STR_DB_File = $CFG->{"database"}->{"file"};
my $GBL_STR_DB_User = $CFG->{"database"}->{"user"};
my $GBL_STR_DB_Pass = $CFG->{"database"}->{"pass"};
my $GBL_BOOL_DB_Err = $CFG->{"database"}->{"err"};
my $GBL_STR_DB_Host = $CFG->{"database"}->{"host"};
my $GBL_STR_DB_Port = $CFG->{"database"}->{"port"};
{
if($GBL_STR_DB_Type eq "MySQL") {
$DB = DBI->connect("DBI:mysql:database=$GBL_STR_DB_File;host=$GBL_STR_DB_Host;port=$GBL_STR_DB_Port","$GBL_STR_DB_User","$GBL_STR_DB_Pass",{
RaiseError => $GBL_BOOL_DB_Err,
AutoCommit => 0
}) or die DBI::errstr;
}
elsif($GBL_STR_DB_Type eq "SQLite") {
$DB = DBI->connect("dbi:$GBL_STR_DB_Type:dbname=$GBL_STR_DB_File.db","$GBL_STR_DB_User","$GBL_STR_DB_Pass",{
RaiseError => $GBL_BOOL_DB_Err,
AutoCommit => 0
}) or die DBI::errstr;
}
# Create and Drop database !
$DB->do($RequeteSQL{$GBL_STR_DB_Type}{dropHUB});
$DB->do($RequeteSQL{$GBL_STR_DB_Type}{createHUB});
$DB->do($RequeteSQL{$GBL_STR_DB_Type}{dropROBOT});
$DB->do($RequeteSQL{$GBL_STR_DB_Type}{createROBOT});
$DB->do($RequeteSQL{$GBL_STR_DB_Type}{dropPROCESSES});
$DB->do($RequeteSQL{$GBL_STR_DB_Type}{createPROCESSES});
$DB->do($RequeteSQL{$GBL_STR_DB_Type}{dropPROBE});
$DB->do($RequeteSQL{$GBL_STR_DB_Type}{createPROBE});
$DB->do($RequeteSQL{$GBL_STR_DB_Type}{dropPKG});
$DB->do($RequeteSQL{$GBL_STR_DB_Type}{createPKG});
$DB->do($RequeteSQL{$GBL_STR_DB_Type}{dropMISSING});
$DB->do($RequeteSQL{$GBL_STR_DB_Type}{createMISSING});
$DB->do($RequeteSQL{$GBL_STR_DB_Type}{dropCONF});
$DB->do($RequeteSQL{$GBL_STR_DB_Type}{createCONF});
$DB->commit or die DBI->errstr;
}
# ************************************************* #
# Commands line option !! (-h == help, -f == robotfile)
# ************************************************* #
my $FILENAME;
if(scalar @ARGV > 0) {
if(($ARGV[0] eq "-f" || $ARGV[0] eq "--f") and exists $ARGV[1]) {
$RobotTXT = 1;
$FILENAME = $ARGV[1];
if(open(my $robotlist, '<:encoding(UTF-8)',$FILENAME)) {
my $row;
while($row = <$robotlist>) {
$row =~ s/;//g;
$row =~ s/,//g;
$row =~ s/^\s+|\s+$//g;
my $new_row = lc $row;
$RobotsHash_TXT{"$new_row"} = 0;
}
}
else {
warn "Could not open robots file $FILENAME";
exit(1);
}
}
else {
warn "This script argument doesn't exist! Please check help.html.";
exit(1);
}
}
else {
$NMS_Probe->localLog("No script argument!",2);
}
# ************************************************* #
# Get HUBS
# ************************************************* #
sub doWork() {
my $NMS_HUB_RES;
my ($FINAL_RC_HUB,$RC) = NIME_ERROR;
for(my $i = 1;$i <= 3;$i++) {
($RC,$NMS_HUB_RES) = Libs::Tools::Request("$GBL_STR_RemoteHUB","gethubs");
if($RC == NIME_OK) {
$FINAL_RC_HUB = NIME_OK;
last;
}
else {
$NMS_Probe->localLog("$GBL_STR_RemoteHUB not responding (timed out). [try $i]",1);
}
}
if($FINAL_RC_HUB == NIME_OK) {
if(scalar keys %GBL_Hash_Hubs > 0 or $hubs_restrict == 0) {
my $HUBS_PDS = Nimbus::PDS->new($NMS_HUB_RES);
# ************************************************* #
# Récupérer les hubs !
# ************************************************* #
my @HubsList = ();
my $HUBID_Count = 0;
for( my $count = 0; my $HUBNFO = $HUBS_PDS->getTable("hublist",PDS_PDS,$count); $count++) {
$HUBID_Count++;
my $HUB = new Nimprobe::hub($HUBID_Count,$HUBNFO);
next if $HUB->{domain} ne $domain;
if($hubs_restrict) {
if(exists $GBL_Hash_Hubs{$HUB->{name}}) {
if(not $GBL_Hash_Hubs{$HUB->{name}}) {
$NMS_Probe->localLog("$HUB->{name} EXCLUDED from checkconfig pool.",2);
$HUBID_Count--;
next;
}
else {
$NMS_Probe->localLog("$HUB->{name} INCLUDED in the checkconfig pool.",2);
}
}
else {
$NMS_Probe->localLog("$HUB->{name} EXCLUDED from checkconfig pool.",2);
$HUBID_Count--;
next;
}
}
# if(not $HUB->{source}) {}
$HUB->insert($DB);
push(@HubsList,$HUB);
}
$DB->commit;
$NMS_Probe->localLog("Hubs processing done",3);
if(scalar @HubsList == 0) {
$NMS_Probe->localLog("[MAJOR] No hubs find on Nimsoft!",1);
return;
}
# ************************************************* #
# Récupérer les robots de chaque HUB !
# ************************************************* #
my @RobotsList = ();
my $ROBOT_Count = 0;
foreach(@HubsList) {
my $count_retry = 0;
while($count_retry < 1) {
$count_retry++;
my $LOCAL_GetRobots_CallbackTime = time();
my ($RC,$RQ_Robot) = Libs::Tools::Request("/$_->{domain}/$_->{name}/$_->{robotname}/hub","getrobots");
my $LOCAL_GetRobots_End_CallbackTime = sprintf("$GBL_STR_Time_Format",time() - $LOCAL_GetRobots_CallbackTime);
$NMS_Probe->localLog("HUB $_->{name} processing",2);
if($RC == NIME_OK) {
$_->robotCallback($DB,($RC) ? 0 : 1,$LOCAL_GetRobots_End_CallbackTime);
my $ROBOT_PDS = Nimbus::PDS->new($RQ_Robot);
for( my $count = 0; my $ROBOTNFO = $ROBOT_PDS->getTable("robotlist",PDS_PDS,$count); $count++) {
$ROBOT_Count++;
my $robot = new Nimprobe::robot($ROBOT_Count,$_->{id} - 1,$ROBOTNFO);
if (index($robot->{name}, "http") != -1) {
next;
}
if(exists $Excluded_Robots{$robot->{name}}) {
$ROBOT_Count--;
$NMS_Probe->localLog("$robot->{name} is excluded from the pool.",2);
next;
}
if($RobotTXT == 1) {
if( not exists($RobotsHash_TXT{$robot->{name}}) ) {
$ROBOT_Count--;
next;
}
else {
$NMS_Probe->localLog("$robot->{name} is in the list!",3);
}
$RobotsHash_TXT{$robot->{name}} = 1;
}
$robot->insert($DB);
if($robot->{status} =~ /^(0)$/) {
push(@RobotsList,$robot);
Libs::Tools::createDir("Output/$GBL_Time_ExecutionTimeStart/$robot->{name}");
}
}
last;
}
else {
$_->robotCallback($DB,($RC) ? 0 : 1,$LOCAL_GetRobots_End_CallbackTime);
$NMS_Probe->localLog("[CRITICAL] Unable to get robotslist [try $count_retry]",1);
}
$_->robotAll($DB,sprintf("$GBL_STR_Time_Format",time() - $LOCAL_GetRobots_CallbackTime));
$DB->commit;
}
}
$NMS_Probe->localLog("All robots processing done",3);
# ************************************************* #
# Récupérer les probes ainsi que les configurations de celle-nécessaire !
# ************************************************* #
if($conf_commit) {
$DB->{AutoCommit} = 1;
}
my $ROBOT_REF = 0;
my @RobotsList_retry = ();
foreach(@RobotsList) {
$ROBOT_REF++;
my $robotInstance = $_;
print "\n";
$NMS_Probe->localLog("Started probe_list for robot $_->{name} [count $ROBOT_REF / $ROBOT_Count]",2);
$NMS_Probe->localLog("Robot version => $_->{version}",2);
if($get_packages) {
$NMS_Probe->localLog("Get packages from robot!",2);
my $PDS = pdsCreate();
my ($PKG_RC,$PKG_OBJ) = nimNamedRequest("$_->{addr}/controller","inst_list_summary",$PDS,1);
pdsDelete($PDS);
my $PKG_CODE = 0;
if($PKG_RC == NIME_OK) {
my $PACKAGE_PDS = Nimbus::PDS->new($PKG_OBJ);
for( my $count = 0; my $PKGNFO = $PACKAGE_PDS->getTable("pkg",PDS_PDS,$count); $count++) {
my $request = $DB->prepare("INSERT INTO packages_list (id,robotid,name,description,version,build,date,install_date) VALUES(NULL,?,?,?,?,?,?,?)");
$request->execute(
$_->{id},
$PKGNFO->get("name"),
$PKGNFO->get("description"),
$PKGNFO->get("version"),
$PKGNFO->get("build"),
$PKGNFO->get("date"),
$PKGNFO->get("install_date")
);
$request->finish;
}
$PKG_CODE = 1;
}
my $rc_robots_pkg = $DB->prepare("UPDATE robots_list SET packages_success=? WHERE id=?");
$rc_robots_pkg->execute($PKG_CODE,$_->{id});
$rc_robots_pkg->finish;
}
my $LOCAL_GetProbes_CallbackTime = time();
my ($RC,$RQ_Probe) = Libs::Tools::Request("$_->{addr}/controller","probe_list");
my $LOCAL_GetProbes_End_CallbackTime = sprintf("$GBL_STR_Time_Format",time() - $LOCAL_GetProbes_CallbackTime);
if($RC == NIME_OK) {
$_->probeCallback($DB,1,$LOCAL_GetProbes_End_CallbackTime);
my $Probe_PDS = Nimbus::PDS->new($RQ_Probe);
my $ProbeNFO = $Probe_PDS->asHash();
# ************************************************* #
# Pour toutes les probes qu'on monitore !
# ************************************************* #
my $FailedsProbes = "";
foreach(@MonitoredProbes) {
# Exclude nt probe on linux
if($robotInstance->{os_minor} eq "Linux") {
if($_ eq "ntservices" || $_ eq "ntevl" || $_ eq "ntperf") {
next;
}
}
# Si la probe existe !
if($ProbeNFO->{$_}) {
my $probeEnv_Name = $_;
my $probe;
$probe = new Nimprobe::probe($robotInstance->{id},$ProbeNFO,$probeEnv_Name);
$probe->insert($DB);
# ************************************************* #
# Récupération des processes
# ************************************************* #
if($get_processes && $_ eq "processes") {
my ($RC,$Res) = Libs::Tools::Request("$robotInstance->{addr}/processes","list_processes");
if($RC == NIME_OK) {
my $Hash = Nimbus::PDS->new($Res)->asHash();
my $count = scalar keys %{ $Hash };
$NMS_Probe->localLog("[SUCCESS] Successfully retrieved $count profiles",3);
foreach my $id (keys %{ $Hash }) {
my $INSERT_CONF = $DB->prepare("INSERT INTO processes (id,robotid,executable,command_line,binary_path,user,short_executable) VALUES(NULL,?,?,?,?,?,?)");
$INSERT_CONF->execute(
$robotInstance->{id},
$Hash->{$id}->{executable},
$Hash->{$id}->{command_line},
$Hash->{$id}->{binary_path},
$Hash->{$id}->{user},
$Hash->{$id}->{short_executable}
);
$INSERT_CONF->finish;
}
}
else {
$NMS_Probe->localLog("[ERR] Failed to get processes list.",1);
}
}
# ************************************************* #
# Récupération et parsing des configurations de sonde Nimsoft !
# ************************************************* #
my $probeGroupe = lc $probe->{group};
my $tempGroup = "probes/$probeGroupe/$_/";
my $configName = $probe->{config};
my $logName = "$probe->{name}.log";
if($probe->{name} eq "hub") {
$tempGroup = "hub";
$configName = "hub.cfg";
$logName = "hub.log";
}
if($probe->{name} eq "controller") {
$tempGroup = "robot";
$configName = "controller.cfg";
$logName = "controller.log"
}
if($probe->{name} eq "nas") {
$tempGroup = "probes/service/$probe->{name}/";
}
my $IHUB = $HubsList[$robotInstance->{hubid}];
# ************************************************* #
# Récupération de la configuration
# ************************************************* #
if($GetRobotConfiguration) {
my $PDS_args = pdsCreate();
pdsPut_PCH ($PDS_args,"directory","$tempGroup");
pdsPut_PCH ($PDS_args,"file","$configName");
pdsPut_INT ($PDS_args,"buffer_size",10000000);
my $LOCAL_GetConf_CallbackTime = time();
my $RC_CONF = NIME_ERROR;
my $RC_W;
my $ProbePDS_CFG;
for(my $i = 1;$i <= 3;$i++) {
($RC_W, $ProbePDS_CFG) = nimNamedRequest("$robotInstance->{addr}/controller", "text_file_get", $PDS_args,3);
if($RC_W == NIME_OK) {
$RC_CONF = NIME_OK;
last;
}
}
pdsDelete($PDS_args);
my $LOCAL_GetConf_End_CallbackTime = sprintf("$GBL_STR_Time_Format",time() - $LOCAL_GetConf_CallbackTime);
if($RC_CONF == NIME_OK) {
$NMS_Probe->localLog("[SUCCESS] download configuration of $_",3);
$probe->callbackCONF($DB,1,$LOCAL_GetConf_End_CallbackTime);
my $completePath = "Output/$GBL_Time_ExecutionTimeStart/$robotInstance->{name}/$probe->{config}";
if($probe->scanCONF($ProbePDS_CFG,$completePath)) {
$probe->parseCONF($DB);
$NMS_Probe->localLog("[SUCCESS] Parse $_ configuration.",3);
}
else {
$NMS_Probe->localLog("[ERR] Parse $_ configuration.",1);
}
}
else {
$probe->callbackCONF($DB,0,$LOCAL_GetConf_End_CallbackTime);
$NMS_Probe->localLog("[ERR] to get conf of $_");
}
}
# ************************************************* #
# Récupération de la log
# ************************************************* #
if($get_probes_log) {
my $log_pds = pdsCreate();
pdsPut_PCH ($log_pds,"directory","$tempGroup");
pdsPut_PCH ($log_pds,"file","$logName");
pdsPut_INT ($log_pds,"buffer_size",10000000);
my ($RC_LOG, $LOGPDS) = nimNamedRequest("$robotInstance->{addr}/controller", "text_file_get", $log_pds,3);
pdsDelete($log_pds);
if($RC_LOG == NIME_OK) {
my $CFG_Handler;
my $completePath = "Output/$GBL_Time_ExecutionTimeStart/$robotInstance->{name}/$logName";
unless(open($CFG_Handler,">>","$completePath")) {
warn "\nUnable to create log file\n";
return 0;
}
my @ARR_CFG_Config = Nimbus::PDS->new($LOGPDS)->asHash();
print $CFG_Handler $ARR_CFG_Config[0]{'file_content'};
close $CFG_Handler;
$NMS_Probe->localLog("[SUCCESS] Download log of => $logName",3);
}
else {
$NMS_Probe->localLog("[ERR] Download log of => $logName",3);
}
}
if($get_probes_log || $GetRobotConfiguration) {
$NMS_Probe->localLog("----------------------------->",3);
}
}
else {
$FailedsProbes.= "$_,";
my $missing_probes;
$missing_probes = $DB->prepare("INSERT INTO missing_probes(robotid,name) VALUES (?,?)");
$missing_probes->execute($robotInstance->{id},$_);
$missing_probes->finish;
}
}
if(length($FailedsProbes) > 0) {
$NMS_Probe->localLog("Failed probelist => $FailedsProbes",2);
}
}
else {
if(not $robot_secondcheck) {
$_->probeCallback($DB,0,$LOCAL_GetProbes_End_CallbackTime);
}
$NMS_Probe->localLog("Impossible d'avoir la liste des sondes pour le robot $_->{name}",1);
$NMS_Probe->localLog("Status du robot => $_->{status}",2);
$NMS_Probe->localLog("----------------------------->",3);
if($_->{status} == 0 && $_->{ip} ne "127.0.0.1") {
my $i = 2;
while($i--) {
sleep(1);
}
push(@RobotsList_retry,$robotInstance);
}
$GBL_INT_FailCount++;
}
$NMS_Probe->localLog( "Finish probe_list for robot $_->{name}",3);
}
if(not $conf_commit) {
$DB->commit;
}
print "\n";
}
else {
$NMS_Probe->localLog("Please enter a list of hubs in the configuration file !",1);
}
}
else {
$NMS_Probe->localLog("Unable to get the list of HUBS from => '$GBL_STR_RemoteHUB' ",1);
}
}
doWork();
$NMS_Probe->localLog("Count of robot that fail get_probes callback => $GBL_INT_FailCount",1);
# ************************************************* #
# Reject file for robotslist with -F args
# ************************************************* #
if($RobotTXT == 1) {
$NMS_Probe->localLog("Generate reject file !",3);
my $file_handler;
unless(open($file_handler,">", $ARGV[2] || "Output/$GBL_Time_ExecutionTimeStart/$GBL_Time_ExecutionTimeStart-reject.txt")) {
warn "Unabled to open rejected_files \n";
return;
}
foreach my $key ( keys %RobotsHash_TXT ) {
if($RobotsHash_TXT{$key} == 0) {
print $file_handler "$key\n";
}
}
close $file_handler;
copy("$FILENAME","Output/$GBL_Time_ExecutionTimeStart/$FILENAME") or warn "Log copy failed! $!";
}
# Create SQLite view
if($GBL_STR_DB_Type eq "SQLite") {
$NMS_Probe->localLog("Create SQLite view!",3);
$DB->{AutoCommit} = 0;
my $v1 = $DB->prepare("CREATE VIEW IF NOT EXISTS 't_bp2i_nimsoft_doublon' AS SELECT name, count(name) as count FROM robots_list GROUP BY name ORDER BY count DESC");
$v1->execute();
$v1->finish;
my $v2 = $DB->prepare("CREATE VIEW IF NOT EXISTS 't_bp2i_nimsoft_conf' AS SELECT robot.name, config.probe, config.profile FROM probes_config config JOIN probes_list probe ON probe.id = config.probeid JOIN robots_list robot ON robot.id = probe.robotid");
$v2->execute();
$v2->finish;
my $v3 = $DB->prepare("CREATE VIEW IF NOT EXISTS 't_bp2i_nimsoft_probes_list' AS SELECT '/' || hubs.domain || '/' || hubs.name || '/' || robots.name as ADDR, probes.name, probes.versions, probes.process_state FROM probes_list probes JOIN robots_list robots ON robots.id = probes.robotid JOIN hubs_list hubs ON hubs.id = robots.hubid");
$v3->execute();
$v3->finish;
my $v4 = $DB->prepare("CREATE VIEW IF NOT EXISTS 't_bp2i_nimsoft_missingprobes' AS SELECT robot.name AS robotname,missing.name AS probeName FROM missing_probes missing JOIN robots_list robot ON robot.id = missing.robotid");
$v4->execute();
$v4->finish;
my $v5 = $DB->prepare("CREATE VIEW IF NOT EXISTS 't_bp2i_nimsoft_robotsdown' AS SELECT * FROM robots_list WHERE status='2'");
$v5->execute();
$v5->finish;
my $v6 = $DB->prepare("CREATE VIEW IF NOT EXISTS
't_bp2i_nimsoft_diffversion_count'
AS
SELECT
RL.name as RobotName,RL.status,RL.os_minor,P.name,P.versions,P.build
FROM
probes_list P
INNER JOIN
robots_list RL ON RL.id = P.robotid
WHERE
(P.name = 'cdm' AND ( P.versions != '5.40HF3MET06' OR P.build != 4 ) ) OR
(P.name = 'ntevl' AND (P.versions != '4.22-HF1' OR P.build != 1) ) OR
(P.name = 'logmon' AND (P.versions != '3.55' OR P.build != 5 ) ) OR
(P.name = 'dirscan' AND (P.versions != '3.14' OR P.build != 18 ) ) OR
(P.name = 'ntservices' AND (P.versions != '3.24HF' OR P.build != 2) ) OR
(P.name = 'ntperf' AND (P.versions != '1.89' OR P.build != 24 ) ) OR
(P.name = 'processes' AND ( P.versions != '4.31-HF' OR P.build != 271 ) )");
$v6->execute();
$v6->finish;
$DB->commit;
}
$DB->disconnect;
# Move checkconfig.db if dataType == SQLite !
if($GBL_STR_DB_Type eq "SQLite"){
$NMS_Probe->localLog("Copy SQLite database to the local execution directory!",3);
copy("$GBL_STR_DB_File.db","Output/$GBL_Time_ExecutionTimeStart/$GBL_STR_DB_File.db") or warn "SQLite database copy failed: $!";
}
copy("checkconfig.log","Output/$GBL_Time_ExecutionTimeStart/checkconfig.log") or warn "Log copy failed! $!";
# ************************************************* #
# Fin du script
# ************************************************* #
$NMS_Probe->close();
my $GBL_Time_ScriptExecutionTime_End = time();
my $FINAL_TIME = sprintf("$GBL_STR_Time_Format", $GBL_Time_ScriptExecutionTime_End - $GBL_Time_ScriptExecutionTime);
print "\nFinal execution time = $FINAL_TIME second(s) !\n";
1;
__END__