-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbbrmq.pl
executable file
·4996 lines (4576 loc) · 171 KB
/
bbrmq.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
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
################################################################################
#
# xymon remote mq monitoring
#
# -----------------------------------------------------------------------------
# Description:
#
# -----------------------------------------------------------------------------
# Notes:
# following HTML Style is needed in xymonmq.css
# table.top { width:100%; }
# td.top {
# width:100px; text-align:center;
# padding-left:5px; padding-right:5px;}
# th.head {
# text-align:left;}
# td.left {
# text-align:left;
# padding-left:5px; padding-right:5px; }
# td.right {
# text-align:right;
# padding-left:5px; padding-right:5px; }
# td.center {
# text-align:right;
# padding-left:5px; padding-right:5px; }
# td.na {
# background-color:DimGray; color:white;
# padding-left:5px; padding-right:5px; }
# td.ok {
# background-color:green; color:black;
# padding-left:5px; padding-right:5px; }
# td.war {
# background-color:yellow; color:black;
# padding-left:5px; padding-right:5px; }
# td.err {
# background-color:Crimson; color:white;
# padding-left:5px; padding-right:5px; }
# td.ign {
# background-color:blue; color:white;
# padding-left:5px; padding-right:5px; }
# td.tig {
# background-color:WhiteSmoke; color:black;
# padding-left:5px; padding-right:5px; }
# td.org-ok {
# border:4px solid green;
# padding-left:5px; padding-right:5px; }
# td.org-war {
# border:4px solid yellow;
# padding-left:5px; padding-right:5px; }
# td.org-err {
# border:4px solid red;
# padding-left:5px; padding-right:5px; }
# hostsvc_header needs a link to xymonmq.css
#
# -----------------------------------------------------------------------------
# Functions:
# - logger 2.05.00
# - logfdc 2.05.00
# - newHash 2.00.00
# - sendSigHup 2.03.00
# - sigInt() 2.03.00
# - sigHup() 2.03.00
# - usage 2.00.02
# - cleanUp 2.10.08
# - listCfg 2.00.02
# - setTmpIgn 2.00.02
# - setTmpEnable 2.10.07
# - getTmpIgn 2.00.03
# - getTmpEnb 2.10.07
# - printHash 2.00.00 (for dbg only)
# - getCfg 2.00.00
# - xml2hash 2.00.00
# - expandHash 2.05.00
# - mergeHash 2.00.00
# - connQmgr 2.00.00
# - checkCfg 2.17.00
# - getPlatform 2.00.00
# - cfg2conn 2.00.00
# - getObjState 2.00.00
# - shrinkAttr 2.00.00
# - execMqsc 2.00.00
# - joinQlstat 2.04.00
# - joinChStat 2.04.00
# - joinLsStat 2.10.00
# - parseMqsc 2.00.00 2.09.00
# - disQl 2.00.00
# - disXq 2.04.00
# - disQs 2.00.00
# - disQmgrAlias 2.03.00
# - disChl 2.03.00
# - disChs 2.01.00
# - pingChl 2.12.00
# - disQmStat 2.10.00
# - disList 2.10.00
# - disLisStat 2.10.00
# - disServ 2.10.00
# - disServStat 2.10.00
# - stateFromFile 2.12.04
# - stateToFile 2.12.04
# - evalStat 2.00.03
# - evalAttr 2.00.00
# - lev2id 2.03.00
# - cmpTH 2.00.00 2.10.00
# - calcRatio 2.04.00
# - getMonHash 2.00.00
# - checkMonTime 2.00.00
# - enbIgn 2.10.07
# - tree2format 2.00.00
# - printMsg 2.00.04
# - xymonMsg 2.00.03
# - mailMsg 2.06.00
# - sendMail 2.06.00
#
# -----------------------------------------------------------------------------
# History
# 28.10.2016 2.00.00 am Initial Version
# 15.11.2016 2.00.01 am getMonHash bugs solved
# 25.11.2016 2.00.02 am setTmpIgn,
# printMsg,
# xymonMsg
# command line handling
# return 2 rc from getMonHash + getting them in
# getMonHash getTmpMsg
# 29.11.2016 2.00.03 am evalStat, xymonMsg _stat->...{ignore} introduced
# 15.12.2016 2.00.04 am show phone nr in header
# 27.12.2016 2.01.00 am disChs for showing SVRCONN
# 13.11.2017 2.03.00 am Unix / direct connection: cfg2conn
# dis{Obj} ping qmgr added for Unix
# monitor trashold for appl->{type}{$type}
# showing queue manager state at the top of xymon
# 27.08.2018 2.04.00 am first productive version
# monitor tag key value swaped to trashhold = level
# handling runmqsc zombies improved
# reconnect counter introduced
# 20.09.2018 2.05.00 am monitoring times as a hash, new format of ini files
# 05.10.2018 2.05.01 am expandHash expands whole tree
# 24.10.2018 2.05.02 am getMonHash obj definition found, checkMonTime
# elsif condition check _defined $_mon added
# calcRatio added for XMITQ
# 06.11.2018 2.05.03 am @import in ini file improved, possible to import stanza
# from any level of the tree
# 08.12.2018 2.05.04 am persistent ingore for combined attributes implemanted
# reset command displayed
# 23.01.2019 2.05.05 am rename $msg / %msg in printMsg to $xymMsg / %xymMsg
# 31.01.2019 2.06.00 am send mail activated
# 31.01.2019 2.06.01 am send mail debugging text to stdout deleted
# 01.02.2019 2.06.02 am imaginary type QLOUT added, can be used to re-route
# xymon messages for QL to SYS-MQ view
# keep tag added to ini file to provide QLOUT
# 05.02.2019 2.07.00 am no execMqsc if send tag is missing (why to calculate
# if nothing to send)
# handling CSQM297I message
# 05.02.2019 2.07.01 am code cleanup dis obj
# new obj type mqSVRCONN equals SVRCONN
# used for duplicating the service
# 20.02.2019 2.07.02 am rename QLOUT to mqQLOCAL
# 19.03.2019 2.07.03 am temporary ignore for comb state bug in evalStat solved
# 12.04.2019 2.08.00 am send to patrol started
# bbrmq.pl with no attributes -> show usage and die
# 10.05.2019 2.08.01 am send to patrol, 1st working version
# 15.05.2019 2.09.00 am Ver. 9.1 AMQ\d{4} Messages replaced by AMQ\d{4}\w
# 22.05.2019 2.09.01 am monitoring time for obj->{attr}{$attr} key/value swaped
# in function getMonHash.
# this error 2.04.00 was produced in Ver 2.04.00
# 07.06.2019 2.09.02 am monitoring time for mail bug solved
# 28.06.2019 2.09.03 am patrol Warnings disabled. bug: OK->WAR->ERR ERR not sent
# 19.07.2019 2.09.04 am getMonHash {obj}{$obj}{attr}{$attr}{monitor}{time}
# 22.07.2019 2.09.05 am evalStat $th not initialized for combine, solved
# 22.07.2019 2.09.06 am getMonHash empty monitor hash on attr level not wokring
# 23.07.2019 2.09.07 am evalStat display empty monitor hash on attr level gray
# 31.07.2019 2.09.08 am qmgr->obj->attr->monitor inherit ->time bug solved
# 02.08.2019 2.09.09 am $_stObj->{attr}{$cmb}{monitor} in evalStat was set to
# SCALAR, the code was comment out.
# 09.08.2019 2.09.10 am bug evaluating levAttr to levObj in evalStat solved
# 12.08.2019 2.10.00 am types QMGR, LISTENER added
# functions( disQmStat, disList, disLisStat, joinLsStat,
# disServ, disServStat )
# cmpTH operator ! introduced
# 19.08.2019 2.10.01 am call logger() from main, logger $par undefined bug
# info column in xymon introduced
# info key in xymon send stanza
# 26.08.2019 2.10.02 am check time, return ON only at the end of the function
# check time only worked by random, depending
# on keys sequnece
# 27.08.2019 2.10.03 am disQmgrAlias rmoved from bbrmq.pl, sub from lib should
# be used
# 10.09.2019 2.10.04 am only allowed cmd attributes possible
# code cleanup
# 15.09.2019 2.10.05 am cmdln bbrmq.pl -ignore ... bug solved
# 18.09.2019 2.10.06 am css moved to xymonmq.css;output in IE & Chrome improved
# 20.09.2019 2.10.07 am enable monitoring
# 28.10.2019 2.10.08 am cleanup old mail files (func clenUp added)
# 12.12.2019 2.10.09 am "))" in conname causes emtpy DESCR
# 12.12.2019 2.10.10 am INITQ type added
# 20.02.2019 2.11.00 am introducing level: "early" for early warning, e.g. used
# for longrty / shorty in channel monitoring to avoid
# yellow alerts on discint=0 after channel has been
# started
# 24.02.2019 2.11.01 am bug solved: temporary ignore for mails not taken
# into account
# 27.02.2019 2.12.00 am ping channel introduced
# default treshold in evalAttr introduced
# 28.02.2019 2.12.01 am ping chl on zos
# dont ping running chl
# 02.03.2019 2.12.02 am OK as ping status not working, solved
# 05.03.2019 2.12.03 am cmpTH undefine / format err
# FORMAT match to ERR level introduced
# print FORMAT err to STDOUT
# pingChl MVS bugs solved
# 12.03.2019 2.12.04 am QTIME1, QTIME2 & co. monitoring introduced
# 2.12.05 am appl name added to the e-mail subject
# 02.04.2019 2.12.06 am PING channel only during office times
# 20.04.2019 2.12.07 am dis qmgr if PING CHL on time out
# TIMEOUT variable introduced
# 21.04.2019 2.12.08 am 2.13.06 functionality removed
# mailMsg bug with undefined $th in report variable
# solved for combined status
# 06.05.2019 2.12.09 am removing debug pinc chl information
# CSQ9006E message handling on ZoS MQSC output
# 06.05.2019 2.12.10 am mailMsg th not defined for combined attribute (SDR/SVR)
# solved
# 27.08.2020 2.13.00 am $key=$val in mailMsg bug solved
# set ignore until green
# don't delete ignore file for files created
# on 1st Jan 197 + max 10 sec
# delete ignore until green file if green.
# 24.09.2020 2.13.01 am set combined attribute on ignore
# 19.11.2020 2.13.02 am mqSDR type added
# 05.05.2021 2.13.03 am keep only first element working solved
# 10.06.2021 2.13.04 am BOQ for Back Out Queues introduced
# 10.08.2021 2.13.05 ef runmqsc path moved to 923
# 20.10.2021 2.13.06 am no object found on zos handling adjusted
# allow '.' (dot) in the application name / needed in ign
# show application in the header of xymon output
# 26.11.2021 2.14.00 am - issues with strict hash-key handling in new
# perl version solved
# - ini-dir and flag-dir changed
# - log-dir introduce
# - type mqQLOCAL removed
# 07.12.2021 2.14.01 am - sort types before sending to xymon (e.g. SDR always at
# top of SVR)
# - check if $_conn exists for $_cfg qmgr == is qmgr
# configured for connect
# 31.03.2022 2.14.02 am - calcRation 4th attribute RATIO-KEY introduced
# 14.10.2022 2.15.00 am - merge with syspmq3 / automatic enable combSTATUS
# on until green
# 19.10.2022 2.15.01 am - ignore empty keep and exclude object array
# 08.02.2022 2.16.00 am - type mqSDR removed
# sendMail CC & BCC added
# 27.02.2022 2.17.00 am - checkCfg introduced
# 01.03.2022 2.17.01 am - printHash level introduced
# - ps command for stop comm replaced by args
# 07.03.2022 2.17.02 am - evalStat fix ignore on object level. tig and ign have
# a higher level as early
# - TIMEOUT vara removed and replaced by $timeA & timeD
# - ps command catches only bbrmq and perl
# 13.03.2022 2.17.03 am - joinChStat, mqSVRCONN regex replaced by eq SVRCONN
# - increase runmqsc timeout from 10 to 20
# - call setMaxFS with 2088960 (2TGB)
# 22.12.2023 2.17.04 am - who is functionality in setTmpIgn()
#
# to be done:
# redesiegn PING
#
#
# BUGS:
# sub cmpTH: check eq and nq first, > and < after it.
# in > < val is checked on digit, th not. th should be checked
#
################################################################################
use strict ;
use warnings ;
BEGIN
{
push @INC, $ENV{HOME}.'/monitor/lib' ;
}
use FileHandle ; # for file handel as object
use IPC::Open2 ; # for runmqsc starting in the background
use POSIX ":sys_wait_h" ; # for no hang on runmqsc in the background
use Sys::Hostname;
use Time::Local ;
use Time::HiRes qw(usleep nanosleep gettimeofday);
use Data::Dumper ;
use xymon ;
use qmgr ;
my $VERSION = "2.17.04" ;
################################################################################
#
# L I B R A R I E S
#
################################################################################
use FileHandle ; # for file handel as object
use IPC::Open2 ; # for runmqsc starting in the background
################################################################################
#
# E N V I R O N M E N T
#
################################################################################
delete $ENV{MQPROMPT} if exists $ENV{MQPROMPT};
my $sysUrl = "https://".hostname().".deutsche-boerse.de/mqmon" ;
################################################################################
#
# C O N S T A N T S
#
################################################################################
my $ON = 1 ;
my $OFF = 0 ;
my $NA = -2;
my $SHW = -1;
my $OK = 0;
my $IGN = 1;
my $TIG = 2; # temporary ignore
my $EARLY = 3; # early warning
my $WAR = 4;
my $ERR = 5;
my $FORMAT = 6;
my %LEV = ( $NA => 'NA' ,
$SHW => 'SHW' ,
$OK => 'OK' ,
$IGN => 'IGN' ,
$TIG => 'TIG' ,
$EARLY => 'EARLY',
$WAR => 'WAR' ,
$ERR => 'ERR' ,
$FORMAT => 'ERR' );
my $TMP = "/home/mqmon/monitor/flag/mqmon" ;
my $PCHTMP = $TMP.'/pingchl' ;
my $LOG = "/home/mqmon/monitor/log/mqmon" ;
my $MAIL_MAX_AGE = 2600000 ; # app 1 Month
my $DOWN = -99 ;
my $START = 0;
my $STOP = 1;
my $RESTART = 2;
my $IGNORE = 3;
my $ENABLE = 4;
my $DISABLE = 5;
my $CHECK = 6;
my $DBG = 99;
my $levelFormat = "|@>|";
################################################################################
#
# G L O B A L S
#
################################################################################
my $cfg = "/home/mqmon/monitor/ini/mqmon/mqmon.ini" ;
my $runmqsc = "/usr/bin/runmqsc -e " ;
my $patrol = "/opt/Patrol/MSEND/PatrolEvent" ;
my $_conn ; # $_conn has to be global so it can be used in the signal handler
# ----------------------------------------------------------
# logger
# ----------------------------------------------------------
my $LF ; # logger file name
################################################################################
#
# S I G N A L S
#
################################################################################
$SIG{HUP} = \&sigHup ;
$SIG{INT} = \&sigInt ;
################################################################################
#
# C O M M A N D L I N E
#
################################################################################
my $mainAttr ;
my $gList = 0 ;
my $gRun ;
my $gDbg = $DOWN ;
my $gIgnAppl ;
my $gIgnQmgr ;
my $gIgnType ;
my $gIgnObj ;
my $gIgnShow ;
my $gIgnAttr ;
my $gIgnTime ;
my $gEnbAppl = 'all' ; # Enable all per default
my $gEnbQmgr = 'all' ; # Enable all per default
my $gEnbType = 'all' ; # Enable all per default
my $gEnbTime = 3600 ; # Default Enable is one hour
my $gDsbQmgr ;
my $gDsbTime ;
my $gChkIni ;
my $argc = scalar @ARGV ;
# ------------------------------------------------------------------------------
# no arguments is not allowed
# ------------------------------------------------------------------------------
&usage() unless scalar @ARGV > 0 ;
# ------------------------------------------------------------------------------
# go through all arguments
# ------------------------------------------------------------------------------
while( defined $ARGV[0] )
{
my $opt = '' ;
# --------------------------------------------------------
# opt starts with -
# --------------------------------------------------------
if( $ARGV[0] =~ s/^-// )
{
$opt = $ARGV[0] ;
}
# --------------------------------------------------------
# ignore ( main attribute)
# --------------------------------------------------------
if( $opt eq 'ignore' )
{
&usage() if defined $mainAttr ;
$mainAttr = $opt;
$gRun = $IGNORE ;
if( defined $ARGV[1] && $ARGV[1] !~ /^-/ )
{
shift @ARGV ;
$gIgnShow = $ARGV[0] ;
if( $gIgnShow eq 'err' )
{
$gIgnShow = $ERR ;
}
elsif( $gIgnShow eq 'war' )
{
$gIgnShow = $WAR ;
}
else
{
&usage() ;
}
}
shift @ARGV;
next ;
}
# --------------------------------------------------------
# enable monitoring ( main attribute )
# ignore temporary and persistent disabeling
# --------------------------------------------------------
if( $opt eq 'enable' )
{
&usage() if defined $mainAttr ;
$mainAttr = $opt ;
$gRun = $ENABLE ;
shift @ARGV;
next ;
}
# --------------------------------------------------------
# disable monitoring ( main attribute )
# disable monitoring for only one queue manager
# avoiding timeouts if queue not accessable
# --------------------------------------------------------
if( $opt eq 'disable' )
{
&usage() if defined $mainAttr ;
$mainAttr = $opt ;
$gRun = $DISABLE ;
shift @ARGV;
next ;
}
# --------------------------------------------------------
# list configuration ( main attribute )
# --------------------------------------------------------
if( $opt eq 'list' )
{
&usage() if defined $mainAttr ;
$mainAttr = $opt;
$gList = 1 ;
shift @ARGV;
next ;
}
# --------------------------------------------------------
# stop monitoring ( main attribute )
# --------------------------------------------------------
if( $opt eq 'stop' )
{
$gRun = $STOP ;
&usage() if defined $mainAttr ;
$mainAttr = $opt;
shift @ARGV;
next ;
}
# --------------------------------------------------------
# start monitoring ( main attribute )
# --------------------------------------------------------
if( $opt eq 'start' )
{
&usage() if defined $mainAttr ;
$mainAttr = $opt;
$gRun = $START ;
shift @ARGV;
next ;
}
# --------------------------------------------------------
# restart monitoring ( main attribute )
# --------------------------------------------------------
if( $opt eq 'restart' )
{
&usage() if defined $mainAttr ;
$mainAttr = $opt;
$gRun = $RESTART ;
shift @ARGV;
next ;
}
# --------------------------------------------------------
# debug monitoring
# main attributes, other main attributes are allowed
# --------------------------------------------------------
if( $opt eq 'dbg' )
{
&usage() if defined $mainAttr ;
$mainAttr = $opt;
$gDbg = $DBG ;
shift @ARGV;
next ;
}
if( $opt eq 'check' )
{
&usage() if defined $mainAttr ;
$mainAttr = $opt;
$gRun = $CHECK ;
shift @ARGV;
next ;
}
# --------------------------------------------------------
# optional attributes with
# main attribute: ignore
# --------------------------------------------------------
if( $mainAttr eq 'ignore' )
{
shift @ARGV ;
# ----------------------------------
# applicaiton name
# ----------------------------------
if( $opt eq 'appl' )
{
&usage() unless defined $ARGV[0] ;
$gIgnAppl = $ARGV[0] ;
shift @ARGV ;
next;
}
# ----------------------------------
# qmgr name
# ----------------------------------
if( $opt eq 'qmgr' )
{
&usage() unless defined $ARGV[0] ;
$gIgnQmgr = $ARGV[0];
shift @ARGV ;
next;
}
# ----------------------------------
# mq object type name
# ----------------------------------
if( $opt eq 'type' )
{
&usage() unless defined $ARGV[0] ;
$gIgnType = $ARGV[0];
shift @ARGV;
next;
}
# ----------------------------------
# mq object name or object parse
# ----------------------------------
if( $opt eq 'obj' )
{
&usage() unless defined $ARGV[0] ;
$gIgnObj = $ARGV[0];
shift @ARGV;
next;
}
# ----------------------------------
# mq object attribute name
# ----------------------------------
if( $opt eq 'attr' )
{
&usage() unless defined $ARGV[0] ;
$gIgnAttr = $ARGV[0] ;
shift @ARGV;
next;
}
# ----------------------------------
# time to ignore
# ----------------------------------
if( $opt eq 'time' )
{
&usage() unless defined $ARGV[0] ;
$gIgnTime = $ARGV[0] ;
shift @ARGV;
next;
}
# ----------------------------------
# all other -> print usage & quit
# ----------------------------------
&usage();
}
# --------------------------------------------------------
# optional attributes with
# main attribute: enable
# --------------------------------------------------------
if( $mainAttr eq 'enable' )
{
shift @ARGV ;
# ----------------------------------
# applicaiton name
# ----------------------------------
if( $opt eq 'appl' )
{
&usage() unless defined $ARGV[0] ;
$gEnbAppl = $ARGV[0] ;
shift @ARGV ;
next;
}
# ----------------------------------
# queue manager name
# ----------------------------------
if( $opt eq 'qmgr' )
{
&usage() unless defined $ARGV[0] ;
$gEnbQmgr = $ARGV[0] ;
shift @ARGV ;
next;
}
# ----------------------------------
# object type name
# ----------------------------------
if( $opt eq 'type' )
{
&usage() unless defined $ARGV[0] ;
$gEnbType = $ARGV[0] ;
shift @ARGV ;
next;
}
# ----------------------------------
# object type name
# ----------------------------------
if( $opt eq 'time' )
{
&usage() unless defined $ARGV[0] ;
$gEnbTime = $ARGV[0] ;
shift @ARGV ;
next;
}
# ----------------------------------
# all other -> print usage & quit
# ----------------------------------
&usage();
}
# --------------------------------------------------------
# optional attributes with
# main attribute: disable
# --------------------------------------------------------
if( $mainAttr eq 'disable' )
{
shift @ARGV ;
# ----------------------------------
# queue manager name
# ----------------------------------
if( $opt eq 'qmgr' )
{
&usage() unless defined $ARGV[0] ;
$gDsbQmgr = $ARGV[0] ;
shift @ARGV ;
next;
}
# ----------------------------------
# queue manager name
# ----------------------------------
if( $opt eq 'time' )
{
&usage() unless defined $ARGV[0] ;
$gDsbTime = $ARGV[0] ;
shift @ARGV ;
next;
}
# ----------------------------------
# all other -> print usage & quit
# ----------------------------------
&usage();
}
# --------------------------------------------------------
# optional attributes with
# main attribute: disable
# --------------------------------------------------------
if( $mainAttr eq 'check' )
{
shift @ARGV ;
# ----------------------------------
# ini file path
# ----------------------------------
if( $opt eq 'ini' )
{
&usage() unless defined $ARGV[0] ;
$gChkIni = $ARGV[0] ;
shift @ARGV ;
next ;
}
&usage();
}
&usage() ;
}
################################################################################
#
# F U N C T I O N S
#
################################################################################
################################################################################
# logger
################################################################################
sub logger
{
my $SYSdate = time() ;
my @SYSdate = localtime $SYSdate;
my $ss = $SYSdate[0] ;
my $mm = $SYSdate[1] ;
my $hh = $SYSdate[2] ;
my $dd = $SYSdate[3] ;
my $MM = $SYSdate[4] + 1 ;
my $YYYY = $SYSdate[5] + 1900 ;
my $wd = $SYSdate[6] ;
my $day = sprintf("%4d-%2d-%2d", $YYYY, $MM, $dd );
my $time = sprintf("%2d:%2d", $hh, $mm) ;
$day =~ s/ /0/g;
$time =~ s/ /0/g;
my $src = [caller(0)]->[1] ;
my $par = [caller(1)]->[3] ; #parent
if( defined $par )
{
$par =~ s/^\w+?::// ;
}
else
{
$par = 'main' ;
}
my $line = [caller(0)]->[2] ;
$LF = $LOG.'/bbrmq.'.$day.'.'.$$.'.log' ;
open FD, ">>$LF" ;
print FD $day ." ".
$time ." ".
$src .":".
$par ."(".
$line .")".
"\n" ;
close FD ;
}
################################################################################
# stack
################################################################################
sub logfdc
{
my $SYSdate = time() ;
my @SYSdate = localtime $SYSdate;
my $ss = $SYSdate[0] ;
my $mm = $SYSdate[1] ;
my $hh = $SYSdate[2] ;
my $dd = $SYSdate[3] ;
my $MM = $SYSdate[4] + 1 ;
my $YYYY = $SYSdate[5] + 1900 ;
my $wd = $SYSdate[6] ;
my $day = sprintf("%4d-%2d-%2d", $YYYY, $MM, $dd );
my $time = sprintf("%2d:%2d", $hh, $mm) ;
$day =~ s/ /0/g;
$time =~ s/ /0/g;
my $FDC = $LOG.'/bbrmq.'.$day.'.'.$$.'.fdc' ;
open FDC, ">>$FDC" ;
print FDC "----------------------------------------";
print FDC "----------------------------------------\n";
print FDC "Program\t\t:".$0."\n";
print FDC "Time Stamp\t: $day $time\n" ;
print FDC "\n----------------------------------------\n";
print FDC "Last Function call: ";
print FDC " sub ". [caller(1)]->[3]."( )\n";
if( [caller(1)]->[4] == 1 )
{
my $i = 1 ;
foreach my $attr (@_)
{
print FDC "--------------------\n" ;
print FDC " attr ".$i." ". ref($attr) ."\n";
print FDC Dumper \$attr ;
$i++;
}
}
print FDC "\nStack:\n";
my @stack ;
my $func = "" ;
for( my $i=0; $func ne "main" ;$i++ )
{
$func = [caller($i)]->[3] ;
$func = "main" unless defined $func ;
$func =~ s/^.+?::// ;
my $line = [caller($i)]->[2] ;
$line = '?' unless defined $line ;
push @stack, $func.":".$line ;
}
my $offset = '' ;
foreach my $item (reverse @stack)
{
print FDC $offset."- ".$item."\n" ;
$offset .= " ";
}
close FDC ;
}
################################################################################
# create a hash as a reference
################################################################################
sub newHash
{
my %h ;
return \%h ;
}
################################################################################
# send signal HUP
################################################################################
sub sendSigHup
{
logger();
foreach my $line (`ps --no-headers -e -o pid,fuid,args`)
{
chomp $line ;
$line =~ /^\s*(\d+)\s+(\d+)\s+(.+)$/;
my $pid = $1;
my $uid = $2;
my $cmd = $3;
next unless $cmd =~ /bbrmq.pl/ ;
next unless $cmd =~ /perl/ ;
next if $pid == $$ ;
print "$pid\t$uid\t$cmd\n";
kill 'HUP', $pid ;
}
}
################################################################################
# signal handler interrupt
################################################################################
sub sigInt()
{
logger();
&sigHup() ;
}
################################################################################
# signal handler hang up
################################################################################
sub sigHup()
{
logger();
foreach my $qmgr ( keys %$_conn)
{
next if $_conn->{$qmgr}{PID} == 0 ;
my $wr = $_conn->{$qmgr}{WR} ;
print $wr "end\n" ;
}
usleep 100000 ;
foreach my $qmgr ( keys %$_conn)
{
my $wr = $_conn->{$qmgr}{WR} ;
my $rd = $_conn->{$qmgr}{RD} ;
close $wr || warn "error closing write pipe to $qmgr" ;
close $rd || warn "error closing read pipe from $qmgr" ;
waitpid $_conn->{$qmgr}{PID}, &WNOHANG;
$_conn->{$qmgr}{PID} = 0;
}
exit 0 ;
}
################################################################################
# program usage
################################################################################
sub usage
{
print "
usage via
bbmq.pl -ignore [err] -appl {APPL} -qmgr {QMGR} -type {TYPE} -obj {OBJECT} \
-attr {ATTR|all|err} -time {TIME}
-ignore set the object to ignore temporary list
-ignore err show only non-green objects
-appl {APPL} ignore only objects for application {APPL}
-qmgr {QMGR} ignore only object on queue manager {QMGR}
-type {TYPE} ignore only objects of type {TYPE}
-obj {OBJECT} ignore only objects matching {OBJECT}
-attr {ATTR} set only attribute {ATTR} to ignore
-attr err set only non-green attributes to ignore
-attr all set all attributes to ignore
-time {TIME} time to ignore: time can have following formats
n[dhm] ignore for next n [d]ays [h]ours [m]minutes
hh:mm ignore until time (today)
MM-DD hh:mm ignore until Date-Time (this year)
YYYY-MM-DD hh:mm ignore until Date-Time
bbmq.pl -enable -appl {APPL|all} -qmgr {QMGR|all} -type {TYPE|all}
bbmq.pl -list
-list list the configuration
If there is only one application, queue manager, object type, object or attribute
than it will be taken automaticly.
" ;
die "\n" ;
}
################################################################################
# cleanup / hause keeping
#
# remove mail files older thean one month
################################################################################
sub cleanUp
{
opendir TMP, $TMP ;
foreach my $file (readdir TMP)
{
next unless -f "$TMP/$file" ;
next if $file =~ /^mqLog\.\w+\.log$/ ;
my $age = time() - (stat "$TMP/$file")[9] ;