CheckSUNWithCMD.java
32.5 KB
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
package com.sitech.ismp.check;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.Vector;
import org.apache.log4j.Logger;
import com.sitech.ismp.app.coll.RPCTarget;
import com.sitech.ismp.coll.CollBase;
import com.sitech.util.Formater;
public class CheckSUNWithCMD {
private Logger logger = Logger.getLogger("COLL");
String PRE_UNITID = "10-20-24"; // sun主机的标识
RPCTarget rpctarget = null;
String neat_host_name = "";
SimpleDateFormat sim = new SimpleDateFormat("MMddHHmmyy");
String curdate = sim.format(new Date());
/**
* 智能巡检错误日志模块 包含:错误日志中是否有硬件错误,错误日志中是否有 CORE_DUMP 的相关故障记录,错误日志中是否有DELAYED_INT
* 相关的故障记录
*/
public Vector getErrpt(HashMap params) {
try {
logger.info("Begin getErrpt...");
init();
CollBase collResult = new CollBase();
String errpt_PRE_UNITID = PRE_UNITID + "-02";
// 检查硬件错误
if (params.get("PM-20-24-001-03") != null
&& params.get("PM-20-24-001-03").equals("1")) {
String harderror = rpctarget.getKPIValue(". ../bin/shell/getSunErrptCount.sh").trim();
if (harderror.equals("0")){
harderror = "NONE";
}
System.out.println("-- harderror:"+harderror);
collResult.addKPI(errpt_PRE_UNITID + ":" + neat_host_name + "-errpt", "PM-20-24-001-03", harderror);
}
return collResult.getKPISet();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/*
* 智能巡检文件系统模块 文件系统、inode使用率是否接近阀值,是否有应该mount,但未mount的文件系统
*/
public Vector getFilesys(HashMap params) {
try {
logger.info("Begin getFilesys");
init();
CollBase collResult = new CollBase();
String fileSys_PRE_UNITID = PRE_UNITID + "-03";
// 文件系统使用率是否接近阀值
if (params.get("PM-20-24-001-06") != null && params.get("PM-20-24-001-06").equals("1")) {
String fileSysList1 = ""; // 使用率超过阀值的文件系统清单
int filesys_used = 85;
if (params.get("FILESYS_USED") != null){
filesys_used = Integer.parseInt((String) params.get("FILESYS_USED"));
}
// 使用率超过阀值的文件系统
Vector harderror = rpctarget.getKPISet("df -k|grep -v Filesystem");
for (int i = 1; i < harderror.size(); i++) {
String fileSys = (String) harderror.get(i);
String fileSysName = split(fileSys, 5).trim();
String percent1Str = split(fileSys, 4).trim();
if (percent1Str.equals("-") || percent1Str.equals("")) {
continue;
}
int percent1 = new Integer(subString(percent1Str)).intValue();
if (percent1 > filesys_used){
fileSysList1 += fileSysName + ":" + percent1Str + ",";
}
}
if (fileSysList1.equals("")){
fileSysList1 = "NONE";
}else{
fileSysList1 = subString(fileSysList1);
}
collResult
.addKPI(fileSys_PRE_UNITID + ":" + neat_host_name
+ "-filesys", "PM-20-24-001-06",fileSysList1);
}
// inode使用率是否接近阀值
if (params.get("PM-20-24-001-05") != null && params.get("PM-20-24-001-05").equals("1")) {
String fileSysList = ""; // inode使用率超过阀值的文件系统清单
int inode_used = 50;
if (params.get("INODE_USED") != null){
inode_used = Integer.parseInt((String) params.get("INODE_USED"));
}
// inode利用率超过阀值的文件系统
Vector inodeList = rpctarget.getKPISet("df -F ufs -o i|grep -v Filesystem");
for (int i = 0; i < inodeList.size(); i++) {
String inodeInfo = (String) inodeList.get(i);
String inodeName = split(inodeInfo, 4);
String inodePercent = split(inodeInfo, 3);
if (inodePercent.equals("-") || inodePercent.equals("")) {
continue;
}
if (Integer.parseInt(subString(inodePercent).trim()) > inode_used) {
fileSysList += inodeName + ":" + inodePercent + ",";
}
}
if (fileSysList.equals("")){
fileSysList = "NONE";
}else{
fileSysList = subString(fileSysList);
}
collResult
.addKPI(fileSys_PRE_UNITID + ":" + neat_host_name
+ "-filesys", "PM-20-24-001-05",fileSysList);
}
return collResult.getKPISet();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/*
* 智能巡检进程模块 包含:进程总数,是否有僵尸进程,是否有父进程为1的非root用户进程存在
*/
public Vector getProcess(HashMap params) {
try {
logger.info("Begin getProcess");
init();
CollBase collResult = new CollBase();
String process_PRE_UNITID = PRE_UNITID + "-04";
// root进程总数
if (params.get("PM-20-24-001-08") != null
&& params.get("PM-20-24-001-08").equals("1")) {
Vector totalprocessV = rpctarget
.getKPISet("ps -ef | grep root |wc -l");
String totalprocess = (String) totalprocessV.elementAt(0);
collResult.addKPI(process_PRE_UNITID + ":" + neat_host_name
+ "-process", "PM-20-24-001-08", totalprocess.trim());
}
// 是否有僵尸进程
if (params.get("PM-20-24-001-09") != null
&& params.get("PM-20-24-001-09").equals("1")) {
Vector zombieprocessV = rpctarget
.getKPISet("ps -ef | grep defunct | grep -v grep | wc -l");
String zombieprocess = (String) zombieprocessV.elementAt(0);
collResult.addKPI(process_PRE_UNITID + ":" + neat_host_name
+ "-process", "PM-20-24-001-09", zombieprocess.trim());
}
// 是否有父进程为1的非root用户进程存在
if (params.get("PM-20-24-001-10") != null
&& params.get("PM-20-24-001-10").equals("1")) {
Vector fatherprocessis1V = rpctarget
.getKPISet("ps -ef|grep -v root|grep -v grep |awk '{if ($3==1) print}'|wc -l");
String fatherprocessis1 = (String) fatherprocessis1V
.elementAt(0);
collResult.addKPI(process_PRE_UNITID + ":" + neat_host_name
+ "-process", "PM-20-24-001-10", fatherprocessis1
.trim());
}
return collResult.getKPISet();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/*
* 智能巡检安装模块 包含:主机Firmware Version微码版本、操作系统版本
*/
public Vector getInstall(HashMap params) {
try {
logger.info("Begin getInstalll");
init();
CollBase collResult = new CollBase();
// 主机微码版本 prtconf | grep -i 'Firmware Version' |awk -F ':' '{print
// $2}'
if (params.get("PM-20-24-001-16") != null
&& params.get("PM-20-24-001-16").equals("1")) {
String install_PRE_UNITID = PRE_UNITID + "-06:"
+ neat_host_name + "-install";
String fireware = rpctarget.getKPIValue("isainfo");
collResult.addKPI(install_PRE_UNITID, "PM-20-24-001-16", split(
fireware, 0));
}
// 操作系统版本
if (params.get("PM-20-21-001-15") != null
&& params.get("PM-20-21-001-15").equals("1")) {
String osverstion = rpctarget.getKPIValue(
"uname -a|awk '{print $3}'").trim();
collResult.addKPI(PRE_UNITID + ":" + neat_host_name
+ "-install", "PM-20-21-001-15", osverstion);
}
return collResult.getKPISet();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/*
* 智能巡检交换空间模块 包含:交换空间使用率
*/
public Vector getInterspace(HashMap params) {
try {
logger.info("Begin getInterspace");
init();
CollBase collResult = new CollBase();
String interspace_PRE_UNITID = PRE_UNITID + "-08";
// 交换空间使用率
if (params.get("PM-20-24-001-22") != null
&& params.get("PM-20-24-001-22").equals("1")) {
// Vector interspaceusedV = rpctarget
// .getKPISet("top -d 1 -n 10 | grep Memory | awk '{print
// $8,$10}'");
Vector interspaceusedV = rpctarget
.getKPISet("/usr/sbin/swap -l|grep -v swapfile|grep -v swaplo|awk '{print $4,$5}'");
String interspaceused = (String) interspaceusedV.elementAt(0);
int size = Integer.parseInt(subString(split(interspaceused, 0)
.trim()));
int free = Integer.parseInt(subString(split(interspaceused, 1)
.trim()));
String percent = (size - free) / size + "";
collResult.addKPI(interspace_PRE_UNITID + ":" + neat_host_name
+ "-interspace", "PM-20-24-001-22", percent);
}
return collResult.getKPISet();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/*
* 智能巡检网络模块 包含:SRC Master 进程是否运行,网络是否有传输错误,loopback/localhost 是否可以解析
*/
public Vector getNetwork(HashMap params) {
try {
logger.info("Begin getNetwork");
init();
CollBase collResult = new CollBase();
String network_PRE_UNITID = PRE_UNITID + "-09:" + neat_host_name
+ "-network";
// SRCMster进程是否运行
if (params.get("PM-20-24-001-27") != null
&& params.get("PM-20-24-001-27").equals("1")) {
Vector srcprocessV = rpctarget
.getKPISet("ps -ef|grep -i /usr/sbin/srcmster|grep -v grep|wc -l");
String srcprocess = ((String) srcprocessV.elementAt(0)).trim();
String srcupornot = "up";
if (srcprocess.equals("0"))
srcupornot = "down";
else
srcupornot = "up";
collResult.addKPI(network_PRE_UNITID, "PM-20-24-001-27",
srcupornot);
}
// 网卡工作模式
String netcard = rpctarget
.getKPIValue("lsattr -El ent0|grep media_speed");
if (params.get("PM-20-24-001-24") != null
&& params.get("PM-20-24-001-24").equals("1")) {
String card_mode = split(netcard, 1).trim();
collResult.addKPI(network_PRE_UNITID, "PM-20-24-001-24",
card_mode);
}
// 网卡当前速率
if (params.get("PM-20-24-001-25") != null
&& params.get("PM-20-24-001-25").equals("1")) {
String card_speed = split(netcard, 2).toLowerCase().trim();
if (card_speed.indexOf("media") > -1)
card_speed = "--";
collResult.addKPI(network_PRE_UNITID, "PM-20-24-001-25",
card_speed);
}
// 缺省网关是否能ping通
if (params.get("PM-20-24-001-26") != null
&& params.get("PM-20-24-001-26").equals("1")) {
String gateway = rpctarget.getKPIValue(
"netstat -rn | grep default|awk '{print $2}'").trim();
String pinggateway = rpctarget
.getKPIValue(
"ping -c 3 " + gateway
+ " |grep loss|awk '{print $7}'")
.trim();
String pinggatewayornot = "Y";
if (pinggateway.equals("0%"))
pinggatewayornot = "Y";
else
pinggatewayornot = "N";
collResult.addKPI(network_PRE_UNITID, "PM-20-24-001-26",
pinggatewayornot);
}
// 网络是否有传输错误(次数)
if (params.get("PM-20-24-001-28") != null
&& params.get("PM-20-24-001-28").equals("1")) {
// String errorsum = rpctarget
// .getKPIValue("netstat -in|grep -v Name|grep -v lo0|grep -v
// '0.0.0.0' |awk '{print $1,$6,$8}'|grep -v '^ $'");
String errorsum = rpctarget
.getKPIValue("netstat -in|grep -v Name|grep -v lo0|grep -v '0.0.0.0' |awk '{print $1,$6,$8}'|awk '{if(($2+$3)>1000) print $1\":\"($2+$3)}'");
if (errorsum.trim().length()==0)
errorsum = "NONE";
collResult.addKPI(network_PRE_UNITID, "PM-20-24-001-28",
errorsum);
}
// localhost是否可以解析
if (params.get("PM-20-24-001-29") != null
&& params.get("PM-20-24-001-29").equals("1")) {
String pinglocalhost = rpctarget
.getKPIValue("ping -c 3 localhost");
String pinghostornot = "Y";
if (pinglocalhost.indexOf("is alive") >= 0)
pinghostornot = "Y";
else
pinghostornot = "N";
collResult.addKPI(network_PRE_UNITID, "PM-20-24-001-29",
pinghostornot);
}
// 收集网络连接总数、各种状态的连接数量
if (params.get("PM-20-24-001-30") != null
&& params.get("PM-20-24-001-30").equals("1")) {
String listencount = rpctarget.getKPIValue(
"netstat -an|grep 'LISTEN'|wc -l").trim();
String estcount = rpctarget.getKPIValue(
"netstat -an|grep 'ESTABLISHED'|wc -l").trim();
String waitcount = rpctarget.getKPIValue(
"netstat -an|grep 'TIME_WAIT'|wc -l").trim();
String closecount = rpctarget.getKPIValue(
"netstat -an|grep 'CLOSE_WAIT'|wc -l").trim();
collResult.addKPI(network_PRE_UNITID, "PM-20-24-001-30",
"LISTEN:" + listencount + "#" + "ESTABLISHED:"
+ estcount + "#" + "TIME_WAIT:" + waitcount
+ "#" + "CLOSE_WAIT:" + closecount);
logger.info("LISTEN:" + listencount + "#" + "ESTABLISHED:"
+ estcount + "#" + "TIME_WAIT:" + waitcount + "#"
+ "CLOSE_WAIT:" + closecount);
}
// 网络端口队列监控
if (params.get("PM-20-24-001-31") != null
&& params.get("PM-20-24-001-31").equals("1")) {
String netqueue = rpctarget
.getKPIValue(
"netstat -n | grep -E 'tcp|udp'|awk '{if($2!=0 || $3!=0) print}'|wc -l")
.trim();
collResult.addKPI(network_PRE_UNITID, "PM-20-24-001-31",
netqueue);
}
// hostname是否可以解析
if (params.get("PM-20-24-001-32") != null
&& params.get("PM-20-24-001-32").equals("1")) {
Vector hostnameV = rpctarget.getKPISet("hostname");
String hostname = (String) hostnameV.elementAt(0);
String pinghostname = rpctarget.getKPIValue("ping -c 3 "
+ hostname);
String pinghostnameornot = "Y";
if (pinghostname.indexOf("is alive") >= 0)
pinghostnameornot = "Y";
else
pinghostnameornot = "N";
collResult.addKPI(network_PRE_UNITID, "PM-20-24-001-32",
pinghostnameornot);
}
return collResult.getKPISet();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/*
* 智能巡检Rootvg模块 包含:RootVG 是否被正确地镜像、rootvg 的启动顺序、rootvg剩余空间检查、是否有stale的pp存在
*/
public Vector getRootvg(HashMap params) {
try {
logger.info("Begin getRootvg");
init();
String rootvg_PRE_UNITID = PRE_UNITID + "-10:" + neat_host_name
+ "-rootvg";
CollBase collResult = new CollBase();
// rootvg是否被正确镜像,如果没有输出则为N
if (params.get("PM-20-24-001-34") != null
&& params.get("PM-20-24-001-34").equals("1")) {
String QUORUM = rpctarget.getKPIValue(
"df -h |sed -n '2p'|grep md|wc -l").trim();
String isCor = "Y";
if (QUORUM.equals("0")) {
isCor = "N";
}
collResult.addKPI(rootvg_PRE_UNITID, "PM-20-24-001-34", isCor);
}
return collResult.getKPISet();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/*
* 智能巡检uptime模块 包含:检查系统多久没有重新启动了
*/
public Vector getUptime(HashMap params) {
try {
logger.info("Begin getUptime");
init();
CollBase collResult = new CollBase();
// 检查系统多久没有重新启动了
if (params.get("PM-20-24-001-52") != null
&& params.get("PM-20-24-001-52").equals("1")) {
String uptime_PRE_UNITID = PRE_UNITID + "-16:" + neat_host_name
+ "-uptime";
String updays = rpctarget
.getKPIValue("uptime|awk '{print $3}'").trim();
collResult.addKPI(uptime_PRE_UNITID, "PM-20-24-001-52", updays)
.trim();
}
return collResult.getKPISet();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/*
* 智能巡检参数检查模块 包含:虚拟内存参数检查、I/O参数检查、网络参数检查
*/
public Vector getCfgparam(HashMap params) {
try {
logger.info("Begin getCfgparam");
init();
CollBase collResult = new CollBase();
return collResult.getKPISet();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/*
* 智能巡检账号模块 包含:用户账号设置、用户组设置、Root用户远程登录限制、系统用户登录限制
*/
public Vector getAccount(HashMap params) {
try {
logger.info("Begin getFullcore");
init();
String account_PRE_UNITID = PRE_UNITID + "-20:" + neat_host_name
+ "-account";
CollBase collResult = new CollBase();
// 是否能列出所有用户
if (params.get("PM-20-24-001-64") != null
&& params.get("PM-20-24-001-64").equals("1")) {
String lsusercount = rpctarget.getKPIValue(
"lsuser -a home ALL|wc -l").trim();
String passwdcount = rpctarget.getKPIValue1(
"cat /etc/passwd|wc -l").trim();
String isAccord = "Y";
if (Integer.parseInt(lsusercount) != Integer
.parseInt(passwdcount))
isAccord = "实际用户数:" + passwdcount + ",列出用户数:" + lsusercount;
collResult.addKPI(account_PRE_UNITID, "PM-20-24-001-64",
isAccord);
}
// 是否有无用用户组
if (params.get("PM-20-24-001-65") != null
&& params.get("PM-20-24-001-65").equals("1")) {
String unusegroups = rpctarget
.getKPIValue1("cat /etc/group|grep -vE 'uucp|printq'|awk -F \":\" '{if($4==\"\") print $1}'");
if (unusegroups.length() == 0)
unusegroups = "N";
collResult.addKPI(account_PRE_UNITID, "PM-20-24-001-65",
unusegroups);
}
// 是否限制root用户远程登录
if (params.get("PM-20-24-001-66") != null
&& params.get("PM-20-24-001-66").equals("1")) {
String rootRlogin = rpctarget
.getKPIValue1("cat /etc/ssh/sshd_config|grep PermitRootLogin|grep -v just|awk '{print $2}'");
if (rootRlogin.trim().equals("no"))
rootRlogin = "Y";
else
rootRlogin = "N";
collResult.addKPI(account_PRE_UNITID, "PM-20-24-001-66",
rootRlogin);
}
// 是否限制系统用户登录
if (params.get("PM-20-24-001-67") != null
&& params.get("PM-20-24-001-67").equals("1")) {
String sysuserLogin = rpctarget
.getKPIValue1("lsuser -a login ALL|grep -E \"daemon|bin|sys|adm|uucp|nuucp|printq|guest|nobody|lpd|sshd\"|awk '$0 ~ /true/ {print $1}'");
if (sysuserLogin.trim().length() == 0)
sysuserLogin = "Y";
collResult.addKPI(account_PRE_UNITID, "PM-20-24-001-67",
sysuserLogin);
}
// 用户umask值设置是否合规
if (params.get("PM-20-24-001-68") != null
&& params.get("PM-20-24-001-68").equals("1")) {
String umaskRoot = rpctarget
.getKPIValue("lsuser -a umask root|awk '$0 !~ /27/ {print $1}'");
String umaskElse = rpctarget
.getKPIValue1("lsuser -a umask ALL|grep -v root|awk '$0 !~ /22/ {print $1}'");
String umaskSet = umaskRoot + umaskElse;
if (umaskSet.trim().length() == 0)
umaskSet = "Y";
collResult.addKPI(account_PRE_UNITID, "PM-20-24-001-68",
umaskSet);
}
return collResult.getKPISet();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/*
* 智能巡检口令模块 包含:空口令账号、口令生存期安全、口令历史安全、口令锁定策略、口令到期安全、访问权限安全、FTP访问安全
*/
public Vector getPassword(HashMap params) {
try {
logger.info("Begin getFullcore");
init();
String password_PRE_UNITID = PRE_UNITID + "-21:" + neat_host_name
+ "-password";
CollBase collResult = new CollBase();
// 口令生存期安全设置是否合规
if (params.get("PM-20-24-001-71") != null
&& params.get("PM-20-24-001-71").equals("1")) {
String histexpire = (String) params.get("histexpire");
String histexpireChk = rpctarget.getKPIValue1(". ../bin/shell/pwdHistexpire.sh");
if (histexpireChk.trim().length() == 0)
histexpireChk = "Y";
collResult.addKPI(password_PRE_UNITID, "PM-20-24-001-71",histexpireChk);
}
// 用户口令设置是否合规
if (params.get("PM-20-24-001-70") != null
&& params.get("PM-20-24-001-70").equals("1")) {
String secCfg = (String) params.get("secCfg");
String secChk = rpctarget
.getKPIValue1(". ../bin/shell/secPwd.sh " + secCfg);
collResult.addKPI(password_PRE_UNITID, "PM-20-24-001-70",
secChk);
}
// 口令历史安全设置是否合规
if (params.get("PM-20-24-001-72") != null
&& params.get("PM-20-24-001-72").equals("1")) {
String histsize = (String) params.get("histsize");
String histsizeChk = rpctarget
.getKPIValue1(". ../bin/shell/pwdHistsize.sh "
+ histsize);
if (histsizeChk.trim().length() == 0)
histsizeChk = "Y";
collResult.addKPI(password_PRE_UNITID, "PM-20-24-001-72",
histsizeChk);
}
// 口令锁定策略设置是否合规
if (params.get("PM-20-24-001-73") != null
&& params.get("PM-20-24-001-73").equals("1")) {
String retries = (String) params.get("retries");
String retriesChk = rpctarget
.getKPIValue1(". ../bin/shell/pwdRetries.sh " + retries);
if (retriesChk.trim().length() == 0)
retriesChk = "Y";
collResult.addKPI(password_PRE_UNITID, "PM-20-24-001-73",
retriesChk);
}
// 口令到期安全设置是否合规
if (params.get("PM-20-24-001-74") != null
&& params.get("PM-20-24-001-74").equals("1")) {
String pwdwarntime = (String) params.get("pwdwarntime");
String pwdwarntimeChk = rpctarget
.getKPIValue1(". ../bin/shell/pwdPwdwarntime.sh "
+ pwdwarntime);
if (pwdwarntimeChk.trim().length() == 0)
pwdwarntimeChk = "Y";
collResult.addKPI(password_PRE_UNITID, "PM-20-24-001-74",
pwdwarntimeChk);
}
return collResult.getKPISet();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/*
* 智能巡检服务模块 包含:远程维护安全、禁用服务
*/
public Vector getService(HashMap params) {
try {
logger.info("Begin getFullcore");
init();
String service_PRE_UNITID = PRE_UNITID + "-22:" + neat_host_name
+ "-service";
CollBase collResult = new CollBase();
// 远程维护安全ssh、telnet检查
if (params.get("PM-20-24-001-75") != null
&& params.get("PM-20-24-001-75").equals("1")) {
String chkSer = "";
String isSsh = "";
String isTelnet = "";
String sshSer = rpctarget
.getKPIValue1("ps -elf|grep sshd|grep -v grep|wc -l");
String telnetSer = rpctarget
.getKPIValue1("ps -elf|grep telnetd|grep -v grep|wc -l");
if (sshSer.trim().equals("0"))
isSsh = "N";
else
isSsh = "Y";
if (telnetSer.trim().equals("0"))
isTelnet = "N";
else
isTelnet = "Y";
chkSer = "SSH:" + isSsh + ";Telnet:" + isTelnet;
collResult
.addKPI(service_PRE_UNITID, "PM-20-24-001-75", chkSer);
}
// 无用服务是否已禁用
if (params.get("PM-20-24-001-76") != null
&& params.get("PM-20-24-001-76").equals("1")) {
String sysService = rpctarget
.getKPIValue1(". ../bin/shell/sysService.sh");
collResult.addKPI(service_PRE_UNITID, "PM-20-24-001-76",
sysService);
}
return collResult.getKPISet();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/*
* 智能巡检日志审计模块 包含:安全事件审计
*/
public Vector getLogaudit(HashMap params) {
try {
logger.info("Begin getFullcore");
init();
String logaudit_PRE_UNITID = PRE_UNITID + "-23:" + neat_host_name
+ "-logaudit";
CollBase collResult = new CollBase();
return collResult.getKPISet();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/*
* 智能巡检设备模块 包含:屏幕保护
*/
public Vector getDevice(HashMap params) {
try {
logger.info("Begin getFullcore");
init();
String device_PRE_UNITID = PRE_UNITID + "-24:" + neat_host_name
+ "-device";
CollBase collResult = new CollBase();
// 屏幕保护设置
if (params.get("PM-20-24-001-79") != null
&& params.get("PM-20-24-001-79").equals("1")) {
String screenset = rpctarget
.getKPIValue("cat /etc/profile /etc/environment /etc/security/.profile|grep TMOUT|grep -v '#'|wc -l");
if (screenset.trim().equals("0"))
screenset = "N";
else
screenset = "Y";
collResult.addKPI(device_PRE_UNITID, "PM-20-24-001-79",
screenset);
}
return collResult.getKPISet();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/*
* 智能巡检缓冲区模块 包含:缓冲区溢出
*/
public Vector getCushion(HashMap params) {
try {
logger.info("Begin getCushion");
init();
CollBase collResult = new CollBase();
return collResult.getKPISet();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/*
* 智能巡检补丁模块 包含:操作系统的补丁更新检查、操作系统补丁更新及时性检查
*/
public Vector getMend(HashMap params) {
try {
logger.info("Begin getMend");
init();
CollBase collResult = new CollBase();
return collResult.getKPISet();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public void init() {
rpctarget = new RPCTarget();
rpctarget.setRpcCmd("sh RPCTarget_suport.sh");
// 获取主机名称
String host_name = this.getHostName();
// 得到unit_id中使用的主机名称
neat_host_name = Formater.neatenunitid(host_name);
}
private String getHostName() {
Vector host = rpctarget.getKPISet("uname -a");
String host_name = (String) host.elementAt(0);
host_name = split(host_name, 1);
return host_name;
}
/**
* 如果超出了返回,返回 空串
*/
private String split(String str, int pos) {
StringTokenizer st = new StringTokenizer(str);
Vector values = new Vector();
while (st.hasMoreTokens()) {
values.add(st.nextToken());
}
if (pos >= 0 && pos < values.size()) {
return (String) values.elementAt(pos);
}
return "";
}
public String subString(String str) {
if (str != null && str.length() > 0)
str = str.substring(0, str.length() - 1);
return str;
}
public static void main(String[] args) {
CheckSUNWithCMD cmd = new CheckSUNWithCMD();
HashMap params = new HashMap();
params.put("PM-20-24-001-03", "1");
Vector vector = cmd.getErrpt(params);
System.out.print("-- result size : " + vector.size());
}
}