-
Notifications
You must be signed in to change notification settings - Fork 12
/
check_as400.java
executable file
·1990 lines (1816 loc) · 67.3 KB
/
check_as400.java
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
/*----------------------------------
Nagios Plugin to check an IBM System i (AS/400)
Developed June 2003
After Ver 0.18, Modified by Shao-Pin, Cheng since 2010/06/31
------------------------------------
CHANGE LOG:
0.18.01
*Fix check Expired password
*Added check DB utilization
0.18.02
*Added check QCMN JOB Transaction timeout. (Only check for CUB customize CLP result )
*Added debug check logout "Job ending immediately."
*Added check DISK Status.
0.18.03
*Modified the DSPMSG, see the last message and the number of message needing a reply.
0.18.04
*Added check single ASP used.
*Added check CPUC, when use Dynamic hardware resource, CPU load may need consider Current processing capacity .
0.18.05.03
* Fix some German language definitions, thank Stefan Hlustik
0.18.06
* Fix ASP reach threshold cause monitor data error.
* Added check MIMIX Unprocessed Entry Count. (Note: You should add MIMIX lib to LIBL.)
0.18.07
* Fix V6R1 JOB DB US DBFault check
1.0.0
* Official version 1.0.0 release.
* Fix DSPMSG get null value and correct the message count.
1.0.1
* Added CPU CPUC JOBS ASP MIMIX performance data warning and critical value.
1.1.1
* Added check number of jobs in JOBQ.
1.2.0
* Added check Job Status.
* MIMIX Unprocessed Entry Count add check transfer definition and RJ link state.
1.2.4
* Added French language definitions.
* Fixed check CJ command && parse error.
* Fixed check OUTQ error with V6R1/V7R1. And can specify the library now.
1.2.5
* Added check for iCluster Node Status
* Added check for iCluster Group Status
* Added check for iCluster Switch Readines (Thanks, Mark Watts)
1.2.6
* Added check for top CPU used job.
1.2.7.2
* Added check for work with problems.
* Fixed French language check DISK halt. 1.2.7.1
* Fixed iCluster parse String lost define
1.2.8
* Added check for Number of file members.
1.2.9
* Fixed check MSG for LANG FR/GE string index out of range error.
1.3.1
* Modified check CJ for duplicate jobs, can specify job number for CRITICAL and WARNING value.
1.3.2
* Modified Rocket iCluster checks to recognize Nagios user Not Authorized to iCluster
1.4.2
* Added SSL connection option.
* Fixed user name display in Login ERROR message.
* Fixed Log in failure on 10 character username.
1.4.3
* Added ITALIAN language. (Thanks to Riccardo Morandotti)
* Fixed CJS status
1.4.4
* Fixed CPUT problem on OS V7R2.
* Added check job temporary storage used. (Thanks, BIANCHI Xavier)
1.4.5
* Fixed ASP problem on OS V7R2 (If your OS is V6, you need to change source code. find string "parseWrkAspBrm". *V5R3 +128)
1.4.6
* Fixed ASP CPU JOB problem on OS V7R2
* TLS 1.2 support (If your java version lower then 1.8, you need uncomment sslSocket.setEnabledProtocols(new String[] {"TLSv1.2"}); )10/30/18
1.4.7
* Added CUB check NTDCRAMT (Only for CUB)
1.5.1
* Fixed WRKSYSSTS check problem on V7R3
1.5.2
* Added check for specific messages on log (CKMSG)(2019/08/21 Thanks, j. howell)
* Added check for temp and perm address use (CKADDR) (2019/08/21Thanks, j. howell)
* Added some debug output
--------------------------------------------------------------
Last Modified 2019/06/11 by Shao-Pin, Cheng , Taipei, Taiwan
Mail & PayPal donate: cjt74392@ms10.hinet.net
--------------------------------------------------------------*/
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.Date;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
public class check_as400{
final static String VERSION="1.5.2";
public static void printUsage(){
System.out.println("Usage: check_as400 -H host -u user -p pass [-v var] [-w warn] [-c critical]\n");
System.out.println(" (-h) for detailed help");
System.out.println(" (-V) for version information\n");
}
public static void printUsageDetail(){
System.out.println("Check_as400 Version: "+VERSION);
System.out.println("Usage: check_as400 -H host -u user -p pass [-v var] [-w warn] [-c critical]\n");
System.out.println("Options:\n");
System.out.println("-H HOST\n Name of the host to check");
System.out.println("-u USERNAME\n Username to login to host");
System.out.println("-p PASSWORD\n Password to login to host");
System.out.println("-v STRING\n Variable to check. Valid variables include:");
System.out.println(" AJ = Number of active jobs in system.");
System.out.println(" CJ <job> [-w -c] = Check to see if job <job> is in the system.[Number of ACTIVE <job>]");
System.out.println(" CJS <sbs> <job> [status <STATUS>] [noperm]");
System.out.println(" = Check to see if job is existing in Subsystem and has this status.");
System.out.println(" Job checking can be controlled by :");
System.out.println(" status <status> = any other status goes to critical");
System.out.println(" noperm = don't go to critical if job is not in the system");
//System.out.println(" onlyone = go to critical if job is shown twice otherwise ignore it");
System.out.println(" NOTE: if JobStatus is set, it has highest Priority");
System.out.println(" JOBS = Number of jobs in system.");
System.out.println(" CJM <job> = Check the temporary storage used of job.");
System.out.println(" JOBQ <lib/jobq> = Number of jobs in JOBQ.");
System.out.println(" CPU = CPU load.");
System.out.println(" CPUC <cpuBase> = CPU load, Consider Current processing capacity. (CPU used * VP nums / cpuBase).");
System.out.println(" NOTE: Specify <cpuBase>, EX: You want use 3 CPU only, but VP use more than 3.");
System.out.println(" CPUT <job> = Top CPU used job. The total processing unit time used by the job");
System.out.println(" Specify job name, ex: *ALL or QZ* or QZDASOINIT");
System.out.println(" US = Percent free storage");
System.out.println(" ASP <aspNum> = Check ASP <aspNum> used");
System.out.println(" DISK = Check DISK Status.");
System.out.println(" DB = DB utilization. (Not available after V6R1)");
System.out.println(" DBFault = Pool DB/Non-DB Fault");
System.out.println(" LOGIN = Check if login completes.");
System.out.println(" MSG <user> = Check for any unanswered messages on msg queue <user>");
System.out.println(" Any unanswered messages causes warning status.");
System.out.println(" CKMSG <starttime> <MSGID> [<text string>]");
System.out.println(" = Look for existense of MSGID in the messages since <starttime>");
System.out.println(" starttime can be either hh:mm:ss or epoch time.");
System.out.println(" MSGID is the message identifier.");
System.out.println(" Optionally a text string associated with the MSGID can be specified.");
System.out.println(" Returns CRITICAL if message found.");
System.out.println(" CKADDR [TEMP | PERM]");
System.out.println(" = Checks temporary or permanent address use.");
System.out.println(" OUTQ <queue> = Check outq files, writer and status. No writer, or");
System.out.println(" status of 'HLD' causes warning status. This default");
System.out.println(" behavior can be modified with the following options:");
System.out.println(" nw = Don't go critical when no writer");
System.out.println(" ns = Don't warn if status is 'HLD'");
System.out.println(" nf = Ignore number of files in queue");
System.out.println(" NOTE: threshold values are used on number of files");
System.out.println(" SBS <subsystem> = Check if the subsystem <subsystem> is running.");
System.out.println(" NOTE: specify <subsystem> as library/subsystem");
System.out.println(" PRB = Check if the problem was identified.(Need *WRKPRB ANZPRB/CHGPRB/DLTPRB/SNDSRVRQS auth)");
System.out.println(" FDN = Number of file members; specify library/filename ");
System.out.println(" ---------- VISION MIMIX ----------");
System.out.println(" MIMIX <DG name> = Check MIMIX Data Group Unprocessed Entry Count, Transfer definition, RJ link state.");
System.out.println(" ---------- Rocket iCluster ----------");
System.out.println(" ICNODE = Check for any Inactive or Failed Node status.");
System.out.println(" ICGROUP = Check for any Inactive or Indoubt Group status.");
System.out.println(" ICSWTCHRDY <grp> = Check for multiple conditions for switch readiness.");
//System.out.println(" ---------- CUB check CLP ----------");
//System.out.println(" CMD = Check Disk I/O, Transaction count....(Only for CUB)");
System.out.println(" ");
System.out.println("-h\n Print this help screen");
System.out.println("-V\n Print version information");
System.out.println("-SSL\n Use SSL connection\n NOTE: Need to be one of the first arguments to work");
System.out.println(" This option must import CE to Java first, EX:");
System.out.println(" keytool -import -trustcacerts -keystore /.../security/cacerts -storepass changeit -noprompt -alias xxx -file XXX.cer");
System.out.println("-d\n Be verbose (debug)\n NOTE: Needs to be one of the first arguments to work");
System.out.println("-D\n Be verbose and dump screen outputs (debug)");
System.out.println(" NOTES: Needs to be one of the first arguments to work");
System.out.println(" When things are not working, use this flag, redirect the output to a file and send it to me!");
System.out.println("\nNotes:\n -CPU, DB and US threshold's are decimal, JOBS, JOBQ and OUTQ ... are integers.\n");
}
public static void parseCmdLineArgs(String [] args){
int i=0;
int READY_FLAG=127,CRIT_FLAG=64,WARN_FLAG=32,HOST_FLAG=16,USER_FLAG=8,PASS_FLAG=4,CMD_FLAG=2,ARG_FLAG=1;
int flag=0;
try{
while(flag!=READY_FLAG){
if(args[i].equals("-H")){
ARGS.hostName=args[++i];
flag=flag | HOST_FLAG;
}
else if(args[i].equals("-u")){
ARGS.userName=args[++i];
flag=flag | USER_FLAG;
}
else if(args[i].equals("-p")){
ARGS.passWord=args[++i];
flag=flag | PASS_FLAG;
}
else if(args[i].equals("-d")){
ARGS.DEBUG=true;
}
else if(args[i].equals("-D")){
ARGS.DEBUG=ARGS.DEBUG_PLUS=true;
}
else if(args[i].equals("-SSL")){
ARGS.SSL=true;
}
else if(args[i].equals("-w")){
ARGS.tHoldWarn=(new Double(args[++i])).doubleValue();
flag=flag | WARN_FLAG;
}
else if(args[i].equals("-c")){
ARGS.tHoldCritical=(new Double(args[++i])).doubleValue();
flag=flag | CRIT_FLAG;
}
else if(args[i].equals("-h")){
printUsageDetail();
System.exit(0);
}
else if(args[i].equals("-V")){
System.out.println("");
System.out.println("Check_as400 Version: "+VERSION);
System.out.println("---------------------------");
System.out.println("Check_as400 is Nagios Plugin to check IBM System i. \n");
System.out.println("Feedback and help");
System.out.println("-----------------");
System.out.println("Shao-Pin Cheng, Taipei, Taiwan");
System.out.println("Mail & PayPal donate: cjt74392@ms10.hinet.net");
System.out.println("");
System.exit(0);
}
else if(args[i].equals("-v")){
if(args[++i].equals("CPU")){
ARGS.command=WRKSYSSTS;
ARGS.checkVariable=CPU;
flag=flag | CMD_FLAG | ARG_FLAG;
}
else if(args[i].equals("CPUC")){
ARGS.command=WRKSYSACT;
ARGS.checkVariable=CPUC;
ARGS.cpuNum=args[++i];
flag=flag | CMD_FLAG | ARG_FLAG;
}
else if(args[i].equals("CPUT")){
ARGS.command=TOPCPUJOB;
ARGS.checkVariable=CPUT;
++i;
if (args[i].equals("-w")||args[i].equals("-c")){
ARGS.job="*ALL";
i--;
}
else {
ARGS.job=args[i];
}
flag=flag | CMD_FLAG | ARG_FLAG;
}
else if(args[i].equals("DB")){
ARGS.command=WRKSYSSTS;
ARGS.checkVariable=DB;
flag=flag | CMD_FLAG | ARG_FLAG;
}
else if(args[i].equals("FDN")){
ARGS.command=DSPFD;
ARGS.checkVariable=FDN;
ARGS.fdFile=args[++i];
flag=flag | CMD_FLAG | ARG_FLAG;
}
else if(args[i].equals("US")){
ARGS.command=WRKSYSSTS;
ARGS.checkVariable=US;
flag=flag | CMD_FLAG | ARG_FLAG;
}
else if(args[i].equals("DBFault")){
ARGS.command=WRKSYSSTS;
ARGS.checkVariable=DBFault;
flag=flag | CMD_FLAG | ARG_FLAG;
}
else if(args[i].equals("CMD")){
ARGS.command=CMDCLP;
ARGS.checkVariable=CMD;
ARGS.cmdCL=args[++i];
++i;
while(true){
if(args[i].equals("XXPARM")){
ARGS.cmd_parm=args[i];
ARGS.outQFlags=ARGS.outQFlags | CMDPARM_FLAG;
i++;
}
else{
i--;
break;
}
}
flag=flag | CMD_FLAG | ARG_FLAG;
}
else if(args[i].equals("DTAQD")){
ARGS.command=DSPDTAQD;
ARGS.checkVariable=DTAQD;
ARGS.dtaqdName=args[++i];
flag=flag | CMD_FLAG | ARG_FLAG;
}
else if(args[i].equals("DISK")){
ARGS.command=WRKDSKSTS;
ARGS.checkVariable=DISK;
flag=flag | CMD_FLAG | ARG_FLAG | WARN_FLAG | CRIT_FLAG;
}
else if(args[i].equals("ASP")){
ARGS.command=WRKASPBRM;
ARGS.checkVariable=ASP;
ARGS.aspNums=args[++i];
flag=flag | CMD_FLAG | ARG_FLAG;
}
else if(args[i].equals("PRB")){
ARGS.command=WRKPRB;
ARGS.checkVariable=PRB;
flag=flag | CMD_FLAG | ARG_FLAG | WARN_FLAG | CRIT_FLAG;
}
else if(args[i].equals("MIMIX")){
ARGS.command=DSPDGSTS;
ARGS.checkVariable=MIMIX;
ARGS.dgDef=args[++i];
flag=flag | CMD_FLAG | ARG_FLAG;
}
else if(args[i].equals("AJ")){
ARGS.command=WRKACTJOB;
ARGS.checkVariable=AJOBS;
flag=flag | CMD_FLAG | ARG_FLAG;
}
else if(args[i].equals("JOBS")){
ARGS.command=WRKSYSSTS;
ARGS.checkVariable=JOBS;
flag=flag | CMD_FLAG | ARG_FLAG;
}
else if(args[i].equals("JOBQ")){
ARGS.command=WRKJOBQ;
ARGS.checkVariable=JOBQ;
ARGS.jobQ=args[++i];
flag=flag | CMD_FLAG | ARG_FLAG;
}
else if(args[i].equals("SBS")){
ARGS.command=DSPSBSD;
ARGS.checkVariable=SBS;
ARGS.subSystem=args[++i];
flag=flag | CMD_FLAG | ARG_FLAG | WARN_FLAG | CRIT_FLAG;
}
else if(args[i].equals("CJ")){
ARGS.command=DSPJOB;
ARGS.checkVariable=DJOB;
ARGS.job=args[++i];
flag=flag | CMD_FLAG | ARG_FLAG;
++i;
while(true){
//In this case all further addition parameters are optional
if (i==args.length){
flag=flag | WARN_FLAG | CRIT_FLAG; // Parameter completely set
break;
}
else{
i--;
break;
}
}
}
else if(args[i].equals("CJM")){
ARGS.command=DSPJOBM;
ARGS.checkVariable=DJOBM;
ARGS.job=args[++i];
flag=flag | CMD_FLAG | ARG_FLAG;
}
else if(args[i].equals("LOGIN")){
ARGS.command=CMDLOGIN;
flag=flag | CMD_FLAG | ARG_FLAG | WARN_FLAG | CRIT_FLAG;
}
else if(args[i].equals("MSG")){
ARGS.command=DSPMSG;
ARGS.checkVariable=MSG;
ARGS.msgUser=args[++i];
flag=flag | CMD_FLAG | ARG_FLAG | WARN_FLAG | CRIT_FLAG;
}
else if(args[i].equals("ICNODE")){
ARGS.command=DMWRKNODE;
ARGS.checkVariable=ICNODE;
flag=flag | CMD_FLAG | ARG_FLAG | WARN_FLAG | CRIT_FLAG;
}
else if(args[i].equals("ICGROUP")){
ARGS.command=DMWRKGRP;
ARGS.checkVariable=ICGROUP;
flag=flag | CMD_FLAG | ARG_FLAG | WARN_FLAG | CRIT_FLAG;
}
else if(args[i].equals("ICSWTCHRDY")){
ARGS.command=DMSWTCHRDY;
ARGS.checkVariable=ICSWRDY;
ARGS.icGroup=args[++i];
flag=flag | CMD_FLAG | ARG_FLAG | WARN_FLAG | CRIT_FLAG;
}
else if(args[i].equals("OUTQ")){
ARGS.command=WRKOUTQ;
ARGS.checkVariable=OUTQ;
ARGS.outQ=args[++i];
/*nw = Don't warn when no writer
ns = Don't warn if status is 'HLD'
nf = Ignore number of files in queue*/
++i;
while(true){
if(args[i].equals("nw")){
ARGS.outQFlags=ARGS.outQFlags | OUTQ_NW;
i++;
}
else if(args[i].equals("ns")){
ARGS.outQFlags=ARGS.outQFlags | OUTQ_NS;
i++;
}
else if(args[i].equals("nf")){
ARGS.outQFlags=ARGS.outQFlags | OUTQ_NF;
i++;
flag=flag | WARN_FLAG | CRIT_FLAG;
}
else{
i--;
break;
}
}
flag=flag | CMD_FLAG | ARG_FLAG;
}
else if(args[i].equals("CJS")){
ARGS.command=CHKJOBSTS;
ARGS.checkVariable=JOBSTS;
ARGS.subSystem=args[++i];
ARGS.job=args[++i];
++i;
while(true){
//In this case all further addition parameters are optional
if (i==args.length){
flag=flag | WARN_FLAG | CRIT_FLAG; // Parameter completely set
break;
}
else if(args[i].equals("status")){
ARGS.chk_status=args[++i];
ARGS.JobFlags=ARGS.JobFlags | JOBSTS_STATUS;
i++;
}
else if(args[i].equals("noperm")){
ARGS.JobFlags=ARGS.JobFlags | JOBSTS_NOPERM;
i++;
}
else if(args[i].equals("onlyone")){
ARGS.JobFlags=ARGS.JobFlags | JOBSTS_ONLYONE;
i++;
}
else{
i--;
break;
}
}
flag=flag | CMD_FLAG | ARG_FLAG;
}
/* added jwh - find specific msgid in msgqueue */
else if(args[i].equals("CKMSG")){
ARGS.command=DSPLOG;
ARGS.checkVariable=CKMSG;
ARGS.startTime=parseCKMSGtime(args[++i]);
ARGS.msgID=args[++i];
flag=flag | CMD_FLAG | ARG_FLAG | WARN_FLAG | CRIT_FLAG;
/* optionally can provide search text */
ARGS.srchText="";
int extra=args.length-1;
while (i<extra) {
ARGS.srchText = ARGS.srchText+args[++i]+" ";
}
}
/* added jwh - check temp or perm address use */
else if(args[i].equals("CKADDR")){
ARGS.command=WRKSYSSTS;
ARGS.checkVariable=CKADDR;
ARGS.addrtype=args[++i];
flag=flag | CMD_FLAG | ARG_FLAG;
}
}
else{
System.out.println("Unknown option ["+args[i]+"]");
System.exit(WARN);
}
i++;
}
if(ARGS.checkVariable==US || ARGS.checkVariable==DJOB){
if(ARGS.tHoldWarn<ARGS.tHoldCritical){
System.out.println("Warning threshold should be greater than the Critical threshold.");
System.exit(WARN);
}
}
else if(ARGS.tHoldWarn>ARGS.tHoldCritical){
System.out.println("Warning threshold should be less than the Critical threshold.");
System.exit(WARN);
}
}
catch(Exception e){
printUsage();
/* e.printStackTrace();
System.out.println(e.toString()); */
System.exit(WARN);
}
}
public static void main(String [] args){
ARGS=new check_as400_cmd_vars();
LANG=new check_as400_lang();
parseCmdLineArgs(args);
//establish connection to server
if(ARGS.DEBUG) System.out.print("Establishing connection to server...");
if(open()){
if(ARGS.DEBUG) System.out.println("done.\nLogging in...");
//login
if(login()){
if(ARGS.DEBUG) System.out.println("Login completed.\nSending command ("+ARGS.command+")...");
//send command
String result=runCommand();
if(result!=null){
if(ARGS.DEBUG) System.out.println("Command sent.\nParsing results...");
//parse and disconnect from server
logout(parse(result));
if(ARGS.DEBUG) System.out.println("Finished.");
}
else{
System.out.println("CRITICAL - Unexpected output on command");
logout(CRITICAL);
}
}
else{
System.out.println("CRITICAL - Unexpected output on login");
logout(CRITICAL);
}
}
else
System.exit(CRITICAL);
}
public static String runCommand(){
/*send proper command*/
switch(ARGS.command){
case WRKSYSSTS:
send("wrksyssts astlvl(*intermed)\r");
/*Wait and recieve output screen*/
return waitReceive("===>",NONE);
case WRKOUTQ:
send("wrkoutq "+ARGS.outQ.toLowerCase()+"*\r");
/*Wait and recieve output screen*/
return waitReceive("===>",GETOUTQ);
case DSPMSG:
send("CHGVTMAP DOWN(*CTLD *CTLF *NXTSCR *ESCZ)\r");
waitReceive("F3=",NONE);
//send("dspmsg msgq("+ARGS.msgUser+") msgtype(*INQ) astlvl(*intermed)\r");
send("dspmsg "+ARGS.msgUser+" astlvl(*basic)\r");
/*Wait and recieve output screen*/
return waitReceive("F3=",NONE);
case DSPLOG: /* added jwh - look for specific msgid in msgqueue */
send("CHGVTMAP DOWN(*CTLD *CTLF *NXTSCR *ESCZ)\r");
waitReceive("F3=",NONE);
send("dsplog period(('"+ARGS.startTime+"')) msgid("+ARGS.msgID+")\r");
return waitReceive("F3=",NONE);
case DSPSBSD:
send("dspsbsd sbsd("+ARGS.subSystem+")\r");
/*Wait and recieve output screen*/
return waitReceive("===>",GETSBSD);
case DSPJOB:
send("CHGVTMAP DOWN(*CTLD *CTLF *NXTSCR *ESCZ)\r");
waitReceive("F3=",NONE);
send("dspjob "+ARGS.job+"\r");
/*Wait and recieve output screen*/
waitReceive(LANG.SELECTION,GETJOB);
send("1\r");
return waitReceive("F12=",NONE);
case DSPJOBM:
send("dspjob "+ARGS.job+" \r");
/*Wait and recieve output screen*/
waitReceive(LANG.SELECTION,GETJOBM);
send("3\r");
return waitReceive("F12=",NONE);
case WRKJOBQ:
send("wrkjobq "+ARGS.jobQ+"* \r");
/*Wait and recieve output screen*/
return waitReceive("===>",NONE);
case WRKACTJOB:
send("wrkactjob\r");
/*Wait and recieve output screen*/
return waitReceive("===>",NONE);
case TOPCPUJOB:
send("WRKACTJOB SEQ(*CPU) JOB("+ARGS.job+")\r");
/*Wait and recieve output screen*/
waitReceive("===>",NONE);
//After V7R2 not necessary. send((char)27+"-");
//After V7R2 not necessary. waitReceive("===>",NONE);
send((char)27+"0");
return waitReceive("AuxIO",NONE);
case DSPFD:
send("DSPFD FILE("+ARGS.fdFile+") TYPE(*ATR)\r");
/*Wait and receive output screen*/
waitReceive("F3=",GETFD);
send("+24\r");
return waitReceive("F3=",NONE);
case CHKJOBSTS:
send("wrkactjob sbs("+ARGS.subSystem+") job("+ARGS.job+")\r");
/*Wait and recieve output screen*/
return waitReceive("===>",NONE);
case CMDCLP:
//send("CALL SJLLIB/DISKBUSY\r");
if (ARGS.cmd_parm!=null){
send("CALL "+ARGS.cmdCL+" "+ARGS.cmd_parm+"\r");
/*Wait and recieve output screen*/
return waitReceive("F20=",NONE);
}
else {
send("CALL "+ARGS.cmdCL+" \r");
/*Wait and recieve output screen*/
return waitReceive("F20=",NONE);
}
case DSPDTAQD:
send("DSPDTAQD "+ARGS.dtaqdName+" \r");
/*Wait and recieve output screen*/
return waitReceive("F3=",NONE);
case WRKDSKSTS:
send("CHGVTMAP DOWN(*CTLD *CTLF *NXTSCR *ESCZ)\r");
waitReceive("F3=",NONE);
send("WRKDSKSTS\r");
/*Wait and recieve output screen*/
waitReceive(LANG.REQUEST_WORD,NONE);
send((char)27+"-");
return waitReceive(LANG.DSK_STS_COMPRESSION,NONE);
case WRKASPBRM:
send("CHGVTMAP DOWN(*CTLD *CTLF *NXTSCR *ESCZ)\r");
waitReceive("F3=",NONE);
send("WRKASPBRM ASP("+ARGS.aspNums+")\r");
/*Wait and recieve output screen*/
waitReceive("F3=",NONE);
send((char)27+"-");
return waitReceive("Threshold",NONE);
case WRKSYSACT:
send("WRKSYSACT\r");
/*Wait and recieve output screen*/
return waitReceive("processing",NONE);
case WRKPRB:
send("WRKPRB\r");
/*Wait and recieve output screen*/
return waitReceive("F3=",NONE);
case DSPDGSTS:
send("DSPDGSTS DGDFN("+ARGS.dgDef+") VIEW(*MERGED)\r");
/*Wait and recieve output screen*/
return waitReceive("Restart statistics",NONE);
case DMWRKNODE:
send("CHGCURLIB CURLIB(ICLUSTER)\r");
waitReceive("changed to ICLUSTER",NONE);
send("CALL QCMD \r");
waitReceive("F3=",NONE);
send((char)27+"0");
waitReceive("F3=",NONE);
send("CHGVTMAP DOWN(*CTLD *CTLF *NXTSCR *ESCZ)\r");
waitReceive("F3=",NONE);
send("ICLUSTER/DMWRKNODE \r");
/*Wait and recieve output screen*/
return waitReceive("===>",NONE);
case DMWRKGRP:
send("CHGCURLIB CURLIB(ICLUSTER)\r");
waitReceive("changed to ICLUSTER",NONE);
send("CALL QCMD \r");
waitReceive("F3=",NONE);
send((char)27+"0");
waitReceive("F3=",NONE);
send("CHGVTMAP DOWN(*CTLD *CTLF *NXTSCR *ESCZ)\r");
waitReceive("F3=",NONE);
send("ICLUSTER/DMWRKGRP \r");
/*Wait and recieve output screen*/
return waitReceive("===>",NONE);
case DMSWTCHRDY:
send("CHGCURLIB CURLIB(ICLUSTER)\r");
waitReceive("changed to ICLUSTER",NONE);
send("CALL QCMD \r");
waitReceive("F3=",NONE);
send((char)27+"0");
waitReceive("F3=",NONE);
send("CHGVTMAP DOWN(*CTLD *CTLF *NXTSCR *ESCZ)\r");
waitReceive("F3=",NONE);
send("ICLUSTER/DMSWTCHRDY ICGROUP("+ARGS.icGroup+") \r");
/*Wait and recieve output screen*/
return waitReceive("===>",NONE);
case CMDLOGIN:
System.out.println("OK - Login completed successfully");
logout(OK);
default:
return null;
}
}
public static int parse(String buffer){
switch(ARGS.command){
case WRKSYSSTS:
return parseWrkSysSts(buffer);
case WRKOUTQ:
return parseWrkOutQ(buffer);
case DSPMSG:
return parseDspMsg(buffer);
case DSPSBSD:
return parseDspSbsD(buffer);
case DSPJOB:
return parseDspJob(buffer);
case DSPJOBM:
return parseDspJobM(buffer);
case WRKJOBQ:
return parseWrkJobq(buffer);
case WRKACTJOB:
return parseWrkActJob(buffer);
case TOPCPUJOB:
return parseWrkActJobTop(buffer);
case CMDCLP:
return parseCmdClp(buffer);
case DSPDTAQD:
return parseDspDtaqd(buffer);
case WRKDSKSTS:
return parseWrkDskSts(buffer);
case WRKASPBRM:
return parseWrkAspBrm(buffer);
case WRKSYSACT:
return parseWrkSysAct(buffer);
case DSPDGSTS:
return parseDspDgSts(buffer);
case CHKJOBSTS:
return parseChkJobSts(buffer);
case WRKPRB:
return parseWrkPrb(buffer);
case DSPFD:
return parseDspFd(buffer);
case DMSWTCHRDY:
return parseICSwRdySts(buffer);
case DMWRKGRP:
return parseICGrpSts(buffer);
case DMWRKNODE:
return parseICNodeSts(buffer);
case DSPLOG:
return parseLogSearch(buffer);
}
return UNKNOWN;
}
public static int getStatus(double val){
int returnStatus=UNKNOWN;
if(ARGS.checkVariable==CPU || ARGS.checkVariable==DB || ARGS.checkVariable==JOBS || ARGS.checkVariable==AJOBS || ARGS.checkVariable==OUTQ || ARGS.checkVariable==DBFault || ARGS.checkVariable==CMD || ARGS.checkVariable==ASP || ARGS.checkVariable==CPUC || ARGS.checkVariable==CPUT || ARGS.checkVariable==MIMIX || ARGS.checkVariable==JOBQ || ARGS.checkVariable==FDN || ARGS.checkVariable==DJOBM || ARGS.checkVariable==DTAQD || ARGS.checkVariable==CKADDR){
if(val<ARGS.tHoldWarn){
System.out.print("OK - ");
returnStatus=OK;
}
else if(val>=ARGS.tHoldWarn && val<ARGS.tHoldCritical){
System.out.print("WARNING - ");
returnStatus=WARN;
}
else{
System.out.print("CRITICAL - ");
returnStatus=CRITICAL;
}
}
else if(ARGS.checkVariable==US || ARGS.checkVariable==DJOB){
if(val>ARGS.tHoldWarn){
System.out.print("OK - ");
returnStatus=OK;
}
else if(val<=ARGS.tHoldWarn && val>ARGS.tHoldCritical){
System.out.print("WARNING - ");
returnStatus=WARN;
}
else{
System.out.print("CRITICAL - ");
returnStatus=CRITICAL;
}
}
else
System.out.print("UNKNOWN - ");
return returnStatus;
}
public static int parseDspMsg(String paramString) {
if(paramString.indexOf(LANG.NO_MESSAGES_AVAILABLE)!=-1){
if(paramString.indexOf(LANG.NO_MESSAGES_AVAILABLE)<paramString.indexOf(LANG.MSG_NOT_NEED_REPLY)){
System.out.println("OK - No messages");
return 0;
}
}
//Only display last MSG.
int i = paramString.indexOf(LANG.MSG_NEED_REPLY, 0);
int j = paramString.indexOf(" (", 0);
i += 75;
// case message line begins with (C G D F)
if (j<i){
i = paramString.indexOf(") ", i);
i += 2;
j = paramString.indexOf(".", i);
}
//j -= 1;
String str1 = paramString.substring(i, j);
//Count MSG num
int p=0;
boolean botflag=true;
int count = 0;
while(botflag){
int k = paramString.indexOf("F1=", 0);
k -= 1;
if(paramString.indexOf(LANG.MSG_NOT_NEED_REPLY)!=-1){
botflag=false;
k = paramString.indexOf(LANG.MSG_NOT_NEED_REPLY, 0);
k -= 27;
}
String str3 = paramString.substring(i, k);
String[] str4=new String[str3.length()];
for(int l = 0; l < str4.length;l++) {
str4[l]=str3.substring(l,l+1);
if(str4[l].equals("(")) {
count++;
}
}
send((char)27+"z");
paramString=waitReceive("F3=",NONE);
p++;
}
//MSG detial
try {
String str2 = new String(str1.getBytes("ISO-8859-15"), "UTF-8");
System.out.println(str2+" ( "+count+" MSG need reply) | msgnum="+count+";;;0; ");
}
catch (UnsupportedEncodingException localUnsupportedEncodingException) {
System.err.println(localUnsupportedEncodingException);
}
return 1;
}
public static int parseWrkOutQ(String buffer){
int returnStatus=UNKNOWN;
int start=buffer.indexOf(ARGS.outQ.toUpperCase());
if (ARGS.outQ.toUpperCase().indexOf("/") != -1){
String[] array = ARGS.outQ.toUpperCase().split("/");
start=buffer.indexOf(array[1]);
}
int files=(new Integer((buffer.substring(start+26,start+38)).trim())).intValue();
String writer=(buffer.substring(start+42,start+53)).trim(); //V6 head 44 ok
String status=(buffer.substring(start+60,start+63)).trim(); //V6 end 63 ok
// nw = Don't warn when no writer = 1
// ns = Don't warn if status is 'HLD' = 2
// nf = Ignore number of files in queue = 4
if(writer.equals("[8;64H") || writer.equals("[8;62H")){
if((ARGS.outQFlags & OUTQ_NW)!=OUTQ_NW){
System.out.print("CRITICAL - NO WRITER - ");
returnStatus=CRITICAL;
}
writer="N/A";
status=(buffer.substring(start+54,start+59)).trim();
}
if(returnStatus==UNKNOWN && !(status.equals("RLS"))){
if((ARGS.outQFlags & OUTQ_NS)!=OUTQ_NS){
System.out.print("WARNING - QUEUE NOT RELEASED - ");
returnStatus=WARN;
}
}
if(returnStatus==UNKNOWN && (ARGS.outQFlags & OUTQ_NF)!=OUTQ_NF)
returnStatus=getStatus(files);
if(returnStatus==UNKNOWN){
System.out.print("OK - ");
returnStatus=OK;
}
System.out.println("writer("+writer+") status("+status+") files("+files+")");
return returnStatus;
}
public static int parseDspSbsD(String buffer){
int start=0;
int returnStatus=UNKNOWN;
start=findToken(buffer,":",4)+1;
String status=(buffer.substring(start,start+9)).trim();
if(status.equals(LANG.ACTIVE)){
System.out.print("OK - ");
returnStatus=OK;
}
else{
System.out.print("CRITICAL - ");
returnStatus=CRITICAL;
}
System.out.println("subsystem("+ARGS.subSystem+") status("+status+")");
return returnStatus;
}
public static int parseDspJob(String buffer){
int start=0;
int returnStatus=UNKNOWN;
start=findToken(buffer,":",5)+1;
String status=(buffer.substring(start,start+10)).trim();
if(status.equals(LANG.ACTIVE)){
System.out.print("OK - ");
returnStatus=OK;
}
else{
System.out.print("CRITICAL - ");
returnStatus=CRITICAL;
}
System.out.println("Job("+ARGS.job+") status("+status+")");
return returnStatus;
}
public static int parseDspJobM(String buffer){
int start=0;
int returnStatus=UNKNOWN;
start=findToken(buffer,":",12)+1;
String memoryS=buffer.substring(start,start+12).trim();
String memoryS1=memoryS.replaceAll("\\D(.*)","").trim();
//System.out.println(memoryS1);
int memory=Integer.parseInt(memoryS1);
returnStatus=getStatus(memory);
System.out.println("Temporary storage used by job "+ARGS.job+" : "+memory+" | swap="+memory+";"+ARGS.tHoldWarn+";"+ARGS.tHoldCritical+";0; ");
return returnStatus;
}
public static int parseDspFd(String buffer){
int start=0;
int returnStatus=UNKNOWN;
if(ARGS.checkVariable==FDN){
start=findToken(buffer,":",2)+1;
double fd=(new Double(checkDouble((buffer.substring(start,start+17)).trim()))).doubleValue();
returnStatus=getStatus(fd);
System.out.println(ARGS.fdFile+" Member count "+fd+"| jobs="+fd+";"+ARGS.tHoldWarn+";"+ARGS.tHoldCritical+";0; ");
}
return returnStatus;
}
public static int parseWrkActJob(String buffer){
int start=0;
int returnStatus=UNKNOWN;
start=findToken(buffer,":",7)+1;
if(buffer.indexOf("UTC+")!=-1){
start=findToken(buffer,":",8)+1; //V7R3 or UTC
}
int jobs=(new Integer((buffer.substring(start,start+8)).trim())).intValue();
returnStatus=getStatus(jobs);
System.out.println(jobs+" active jobs in system | jobs="+jobs+";"+ARGS.tHoldWarn+";"+ARGS.tHoldCritical+";0; ");