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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708
|
unset LANG
Scale=2 Unit_1="K" Unit_2="bps"
UseRange="False"
ifIn32="ifInOctets" ifOut32="ifOutOctets"
ifIn64="ifHCInOctets" ifOut64="ifHCOutOctets"
Min_Interval=30 Max_Interval=1800
Timeout=15
print_help_msg(){ print_version $Echo "Usage: $0 -h to get help." $Echo $Echo 'Report bugs to: cloved@gmail.com' $Echo 'Home page: <http://bbs.itnms.info/forum.php?mod=viewthread&tid=767&extra=page%3D1>' $Echo 'Geting help: <http://bbs.itnms.info/forum.php?mod=forumdisplay&fid=10&page=1> or Email to: cloved@gmail.com'
}
print_full_help_msg(){ print_version $Echo "Usage:" $Echo "$0 [ -v ] [ -6 ] [ -i Suffix ] [ -F s|S ] [-p N] [ -r ] -V 1|2c|3 ( -C snmp-community | -A \"AuthString\" (when use snmp v3, U must give the AuthString)) -H host [ -L ] (-I interface|-N interface name) -w in,out-warning-value -c in,out-critical-value -K/M -B/b "
$Echo "Example:" $Echo "${0} -V 2c -C public -H 127.0.0.1 -I 4 -w 200,100 -c 300,200 -K -B" $Echo "Or" $Echo "${0} -V 2c -C public -H 127.0.0.1 -N FastEthernet0/1 -w 200,100 -c 300,200 -K -B" $Echo "Or -r to use Range Value Options:" $Echo "${0} -V 2c -C public -H 127.0.0.1 -I 4 -r -w 200-300,100-200 -c 100-400,50-250 -K -B" $Echo "Or" $Echo "${0} -V 2c -C public -H 127.0.0.1 -N eth0 -r -w 200-300,100-200 -c 100-400,50-250 -K -B" $Echo "Or -p N to use Traffic Jitter Options:" $Echo "${0} -V 2c -C public -H 127.0.0.1 -I 4 -p 8 -w 45,45 -c 55,55" $Echo "Or" $Echo "${0} -V 2c -C public -H 127.0.0.1 -N eth0 -p 8 -w 45,45 -c 55,55" $Echo $Echo "Or for single host and multi interfaces checking (in the same host/device) and traffic aggregation:" $Echo "${0} -V 2c -C public -H 127.0.0.1 -I 2,3,8,9 -w 200,100 -c 300,200 -K -B" $Echo "${0} -V 2c -C public -H 127.0.0.1 -N FastEthernet0/1,FastEthernet0/2 -w 200,100 -c 300,200 -K -B" $Echo "Or -r to use Range Value Options:" $Echo "${0} -V 2c -C public -H 127.0.0.1 -I 2,3,8,9 -r -w 200-300,100-200 -c 100-400,50-250 -K -B" $Echo "${0} -V 2c -C public -H 127.0.0.1 -I -N FastEthernet0/1,FastEthernet0/2 -r -w 200-300,100-200 -c 100-400,50-250 -K -B" $Echo "Or -p N to use Traffic Jitter Options:" $Echo "${0} -V 2c -C public -H 127.0.0.1 -I 2,3,8,9 -p 8 -w 45,45 -c 55,55" $Echo "${0} -V 2c -C public -H 127.0.0.1 -N FastEthernet0/1,FastEthernet0/2 -p 8 -w 45,45 -c 55,55" $Echo $Echo "Or for multi hosts and mult interfaces checking (in the multi hosts/devices) and traffic aggregation:" $Echo "${0} -V 2c,1 -C public,private -H 127.0.0.1,10.76.2.15,10.7.4.18 -I 2,2,1 -w 200,100 -c 300,200 -K -B" $Echo "${0} -V 2c,1 -C public,private -H 127.0.0.1,10.76.2.15,10.7.4.18 -N FastEthernet0/20,FastEthernet0/2,eth0 -w200,100 -c300,200 -KB" $Echo "Or -r to use Range Value Options:" $Echo "${0} -V 2c,1 -C public,private -H 127.0.0.1,192.168.1.1 -I 2,3 -w 200-300,100-200 -c 100-400,50-250 -K -B" $Echo "${0} -V 2c,1 -C public,private -H 127.0.0.1,192.168.1.1 -N FastEthernet0/8,FastEthernet0/2 -r -w 200-300,100-200 -c 100-400,50-250 -K -B" $Echo "Or -p N to use Traffic Jitter Options:" $Echo "${0} -V 2c,1 -C public,private -H 127.0.0.1,192.168.1.1 -I 2,3 -p 8 -w 45,45 -c 55,55" $Echo "${0} -V 2c,1 -C public,private -H 127.0.0.1,192.168.1.1 -N FastEthernet0/21,FastEthernet0/24 -p 8 -w 45,45 -c 55,55" $Echo $Echo "If you do not use -K/M -B/b options, default -K -b, corresponding to Kbps." $Echo "Make sure that the check interval greater than 30 Seconds." $Echo "Or modify the Min_Interval default value as you need " $Echo 'And, if you want in Verbose mode, use -v, to check the debug messages in the file /tmp/check_traffic.$$.' $Echo $Echo "Or use $0 [ -v ] -V 1|2c|3 -C snmp-community -H host -L " $Echo "To list all interfaces on the host." $Echo $Echo "Or check for snmp v3 device:" $Echo "${0} -V 3 -A \"-u kschmidt -l authPriv -a MD5 -A mysecretpass -x DES -X mypassphrase\" -H 127.0.0.1 -I 4 -w 200,100 -c 300,200 -K -B" $Echo "Or" $Echo "${0} -V 3 -A \"-u kschmidt -l authPriv -a MD5 -A mysecretpass -x DES -X mypassphrase\" -H 127.0.0.1 -N eth0 -w 200,100 -c 300,200 -K -B" $Echo $Echo $Echo 'Report bugs to: cloved@gmail.com' $Echo 'Home page: <http://bbs.itnms.info/forum.php?mod=viewthread&tid=767&extra=page%3D1>' $Echo 'Geting help: <http://bbs.itnms.info/forum.php?mod=forumdisplay&fid=10&page=1> or Email to: cloved@gmail.com'
}
print_version(){ $Echo $(cat $0 | head -n 7 | tail -n 1|sed 's/\# //') }
print_err_msg(){ $Echo "Error." print_full_help_msg }
check_record_cnt(){ echo $2 | awk -F "$1" '{print NF}' }
list_interface(){ $SNMPWALK -v $Version $Community $Host "IF-MIB::ifDescr" |sed 's/IF-MIB::ifDescr./Interface index /g' | sed 's/= STRING:/orresponding to /g'
}
get_interface_index(){ intNames="$1" intIndex="" intNameList=$(echo $intNames|sed 's/,/ /g') for intName in $intNameList do intIndex="$intIndex "$($SNMPWALK -v $Version $Community $Host "IF-MIB::ifDescr" |awk -F 'STRING: ' '{if ($2 == "'$intName'")print $0}' | awk -F '=' '{print $1}' | sed 's/IF-MIB::ifDescr.//') done }
gen_string(){ string_num=$1 string_i=1 string_t="" string_p="NA " while [ $string_i -le $string_num ] do string_t="$string_t$string_p" string_i=`expr $string_i + 1` done }
to_debug(){ if [ "$Debug" = "true" ]; then $Echo "$*" >> /tmp/check_traffic.log.$$ 2>&1 if [ "$zDebug" = "true" ]; then $Echo "$*" fi fi }
case "$(uname -s)" in SunOS) Echo="echo" ;; Linux) Echo="echo -e" ;; *) Echo="echo" ;; esac
if [ $# -lt 1 ]; then print_help_msg exit 3 else while getopts :vz6rhi:p:F:V:C:A:H:I:N:LKMBbw:c: OPTION do case $OPTION in v) Debug=true ;; z) zDebug=true ;;
V) Version=$OPTARG if [ $Version == "3" ]; then SnmpVersion=3 fi ;; C) Community=$OPTARG ;; A) AuthString=$OPTARG ;; i) Suffix="$OPTARG" ;; F) Format="$OPTARG" ;; 6) Bit64="True" ;; p) Num="$OPTARG" TrafficJitter="True" ;; r) UseRange="True" ;; H) Host=$OPTARG ;; L) ListInt="True" ;; I) Interface=$OPTARG ;; N) UseIntName="True" InterfaceName=$OPTARG ;; w) WarningV=$OPTARG ;; c) CriticalV=$OPTARG ;; M) isM="True" Unit_1="M" ;; K) ;; B) isB="True" Unit_2="B" ;; b) ;; h) print_full_help_msg exit 3 ;; ?) $Echo "Error: Illegal Option." print_help_msg exit 3 ;; esac done fi
SNMPWALK=`which snmpwalk 2>&1` if [ $? -ne 0 ];then $Echo $SNMPWALK $Echo "Can not found command snmpwalk in you system PATH: $PATH, pleas check it" exit 3 fi SNMPWALK="$SNMPWALK -t $Timeout -Oa" to_debug Use $SNMPWALK to check traffic
SNMPGET=`which snmpget 2>&1` if [ $? -ne 0 ];then $Echo $SNMPGET $Echo "Can not found command snmpget in you system PATH: $PATH, pleas check it" exit 3 fi SNMPGET="$SNMPGET -t $Timeout -Oa" to_debug Use $SNMPGET to check traffic
BC=`which bc 2>&1` if [ $? -ne 0 ];then $Echo $BC $Echo "Can not found command bc in you system PATH: $PATH, pleas check it" exit 3 fi to_debug Use $BC to calculate
if [ ! -z "$Interface" -a ! -z "$InterfaceName" ] ; then $Echo "Please Use -N or -I only" print_help_msg exit 3 fi
mmHostCnt=`check_record_cnt "," "$Host"` mmCommunityCnt=`check_record_cnt "," "$Community"` mmVersionCnt=`check_record_cnt "," "$Version"`
if [ "$UseIntName""ZZ" == "TrueZZ" ]; then Interface="$InterfaceName" fi mmIntCnt=`check_record_cnt "," "$Interface"`
if [ $mmHostCnt -gt 1 ]; then
if [ $mmHostCnt -lt 1 -o $mmCommunityCnt -lt 1 -o $mmVersionCnt -lt 1 -o $mmIntCnt -lt 1 ]; then $Echo "Args Error." print_full_help_msg exit 3 fi if [ $mmHostCnt -ne $mmCommunityCnt -o $mmCommunityCnt -ne $mmVersionCnt -o $mmVersionCnt -ne $mmIntCnt ]; then $Echo "Args Error." print_full_help_msg exit 3 fi
mmHostList=$(echo $Host|sed 's/,/ /g') mmCommunityList=$(echo $Community|sed 's/,/ /g') mmVersionList=$(echo $Version|sed 's/,/ /g') mmIntList=$(echo $Interface|sed 's/,/ /g') mmIntNameList=$(echo $InterfaceName|sed 's/,/ /g') mmHostArray=($mmHostList) mmCommunityArray=($mmCommunityList) mmVersionArray=($mmVersionList) mmIntArray=($mmIntList) mmIntNameArray=($mmIntNameList)
declare -a MMArray Columns=5 Rows=$mmHostCnt
ctbpsIn=0 ctbpsOut=0 ctDiffRIAVG=0 ctDiffROAVG=0 for mmII in `seq 1 $mmHostCnt` do let "aIndex = $mmII - 1" let "mmIndex = $aIndex * $Columns + 0" MMArray[$mmIndex]=${mmHostArray[$aIndex]} Host=${MMArray[$mmIndex]} to_debug MMArray host "${MMArray[$mmIndex]}" let "mmIndex = $aIndex * $Columns + 1" MMArray[$mmIndex]=${mmCommunityArray[$aIndex]} Community=${MMArray[$mmIndex]} to_debug MMArray community "${MMArray[$mmIndex]}" let "mmIndex = $aIndex * $Columns + 2" MMArray[$mmIndex]=${mmVersionArray[$aIndex]} Version=${MMArray[$mmIndex]} to_debug MMArray version "${MMArray[$mmIndex]}" let "mmIndex = $aIndex * $Columns + 3" MMArray[$mmIndex]=${mmIntArray[$aIndex]} Interface=${MMArray[$mmIndex]} to_debug MMArray int "${MMArray[$mmIndex]}" let "mmIndex = $aIndex * $Columns + 4" MMArray[$mmIndex]=${mmIntNameArray[$aIndex]} InterfaceName=${MMArray[$mmIndex]} to_debug MMArray int "${MMArray[$mmIndex]}"
if [ -z "$Version" -o -z "$Host" ] ; then $Echo "Args Error." print_full_help_msg exit 3 fi if [ "$SnmpVersion" = "3" ]; then if [ -z "$AuthString" ]; then $Echo "Args Error." print_full_help_msg exit 3 else Community="$AuthString" fi else if [ -z "$Community" ]; then $Echo "Args Error." print_full_help_msg exit 3 else Community=" -c $Community" fi fi if [ "$UseIntName""ZZ" == "TrueZZ" ]; then get_interface_index $InterfaceName Interface=$intIndex if [ -z "$Interface" -o "$Interface" == " " ] ; then $Echo Can not get the interface index with "$InterfaceName" at "$Host". exit 3 fi Interface=$(echo $Interface|sed 's/ /,/g') fi if [ "$ListInt" = "True" ]; then $Echo "List Interface for host $Host." list_interface exit 3 fi if [ -z "$Interface" -o -z "$WarningV" -o -z "$CriticalV" ] ; then $Echo "Args Error." print_full_help_msg exit 3 fi to_debug All Values are \" Warning: "$WarningV" and Critical: "$CriticalV" \". WVC=`check_record_cnt "," "$WarningV"` CVC=`check_record_cnt "," "$CriticalV"` to_debug WVC is $WVC and CVC is $CVC if [ $UseRange = "True" ] ;then to_debug UseRange is True if [ $WVC -ne 2 -o $CVC -ne 2 ] ; then $Echo "Warning and Critical Value error." print_full_help_msg exit 3 else W1=`echo $WarningV| awk -F "," '{print $1}'` W1b=`echo $W1| awk -F "-" '{print $1}'` W1e=`echo $W1| awk -F "-" '{print $2}'` W2=`echo $WarningV| awk -F "," '{print $2}'` W2b=`echo $W2| awk -F "-" '{print $1}'` W2e=`echo $W2| awk -F "-" '{print $2}'` Wtb=`echo "$W1b + $W2b"|bc` Wte=`echo "$W1e + $W2e"|bc` to_debug Warning Value is $W1 $W2 $Wtb $Wte C1=`echo $CriticalV| awk -F "," '{print $1}'` C1b=`echo $C1| awk -F "-" '{print $1}'` C1e=`echo $C1| awk -F "-" '{print $2}'` C2=`echo $CriticalV| awk -F "," '{print $2}'` C2b=`echo $C2| awk -F "-" '{print $1}'` C2e=`echo $C2| awk -F "-" '{print $2}'` Ctb=`echo "$C1b + $C2b"|bc` Cte=`echo "$C1e + $C2e"|bc` to_debug Critical Value is $C1 $C2 $Ctb $Cte check_1b=`echo "$C1b < $W1b" | bc` check_1e=`echo "$C1e > $W1e" | bc` check_2b=`echo "$C2b < $W2b" | bc` check_2e=`echo "$C2e > $W2e" | bc` to_debug check_1 is $check_1b , $check_1e check_2 is $check_2b $check_2e if [ $check_1b -ne 1 -o $check_1e -ne 1 -o $check_2b -ne 1 -o $check_2e -ne 1 ] ; then $Echo "Error, the corresponding Critical End value must greater than Warning End value, And Critical Begin value must less than Warning End value" print_full_help_msg exit 3 fi fi else to_debug Use Range is False if [ $WVC -ne 2 -o $CVC -ne 2 ] ; then $Echo "Warning and Critical Value error." print_full_help_msg exit 3 else W1=`echo $WarningV| awk -F "," '{print $1}'` W2=`echo $WarningV| awk -F "," '{print $2}'` Wt=`echo "$W1 + $W2"|bc` to_debug Warning Value is $W1 $W2 $Wt C1=`echo $CriticalV| awk -F "," '{print $1}'` C2=`echo $CriticalV| awk -F "," '{print $2}'` Ct=`echo "$C1 + $C2"|bc` to_debug Critical Value is $C1 $C2 $Ct check_1=`echo "$C1 > $W1" | bc` check_2=`echo "$C2 > $W2" | bc` to_debug check_1 is $check_1 , check_2 is $check_2 if [ $check_1 -ne 1 -o $check_2 -ne 1 ] ; then $Echo "Error, the corresponding Critical value must greater than Warning value." print_full_help_msg exit 3 fi fi fi if [ -z $Suffix ]; then Suffix=itnms fi if [ $TrafficJitter"AA" = "TrueAA" ]; then Suffix=${Suffix}J fi if [ $UseRange = "True" ] ;then Suffix=${Suffix}R fi Username=`id --user --name` CF_HIST_DATA="/var/tmp/check_traffic_${Host}_${Interface}_MM_${Username}_${Suffix}.hist_dat" to_debug CF_HIST_DATA "$CF_HIST_DATA" Time=`date +%s` ifName="`$SNMPGET -v $Version $Community $Host IF-MIB::ifDescr.${Interface}| awk -F ":" '{print $4}'`" ifSpeed="`$SNMPGET -v $Version $Community $Host IF-MIB::ifSpeed.${Interface}| awk -F ":" '{print $4}'`" Flag64Content=`$SNMPGET -v $Version $Community $Host IF-MIB::ifHCOutOctets.${Interface} 2>&1` if [ $? -eq 0 ]; then echo $Flag64Content |grep Counter64 >/dev/null 2>&1 Flag64=$? if [ $Flag64 -eq 0 -a "$Version" = "2c" ];then ifIn=$ifIn64 ifOut=$ifOut64 BitSuffix=64 fi else ifIn=$ifIn32 ifOut=$ifOut32 BitSuffix=32 if [ "$Bit64" = "True" ] ;then $Echo "Maybe your Host(device) not support 64 bit counter. Please confirm your ARGS and re-check it with Verbose mode, then to check the log.(If you snmp not support 64 bit counter, do not use -6 option)" exit 3 fi fi CF_HIST_DATA=${CF_HIST_DATA}_${BitSuffix} STAT_HIST_DATA=${CF_HIST_DATA}_ctj_$Num if [ ! -f $CF_HIST_DATA ]; then IsFirst="True" touch $CF_HIST_DATA if [ $? -ne 0 ];then Severity=3 Msg="Unknown" OutPut="Create File $CF_HIST_DATA Error with user `id`." $Echo "$Msg" "-" $OutPut exit $Severity fi fi if [ ! -r $CF_HIST_DATA -o ! -w $CF_HIST_DATA ]; then Severity=3 Msg="Unknown" OutPut="Read or Write File $CF_HIST_DATA Error with user `id`." $Echo "$Msg" "-" $OutPut exit $Severity fi if [ $TrafficJitter"AA" = "TrueAA" ]; then if [ ! -f $STAT_HIST_DATA ]; then touch $STAT_HIST_DATA IsStatFirst="True" if [ $? -ne 0 ];then Severity=3 Msg="Unknown" OutPut="Create File $STAT_HIST_DATA Error with user `id`." $Echo "$Msg" "-" $OutPut exit $Severity fi if [ ! -r $STAT_HIST_DATA -o ! -w $STAT_HIST_DATA ]; then Severity=3 Msg="Unknown" OutPut="Read or Write File $STAT_HIST_DATA Error with user `id`." $Echo "$Msg" "-" $OutPut exit $Severity fi gen_string $Num to_debug string_t $string_t TC=0 TRI=($string_t) TRO=($string_t) echo $TC >$STAT_HIST_DATA echo ${TRI[@]} >>$STAT_HIST_DATA echo ${TRO[@]} >>$STAT_HIST_DATA fi C=(`head -n 1 $STAT_HIST_DATA`) RI=(`head -n 2 $STAT_HIST_DATA|tail -n 1 `) RO=(`tail -n 1 $STAT_HIST_DATA`) to_debug C RI RO $C $RI $RO to_debug C RI RO $C ${RI[@]} ${RO[@]} to_debug C N $C $Num fi _result_status=`$SNMPGET -v $Version $Community $Host "IF-MIB::ifOperStatus.${Interface}"| awk '{print $4}' | awk -F '(' '{print $1}'` if [ "$_result_status" != "up" ]; then $Echo "The Interface name:${ifName} -- index:${Interface} you checked seems not up." exit 3 fi _result_in=`$SNMPGET -v $Version $Community $Host "IF-MIB::${ifIn}"."$Interface"` _result_out=`$SNMPGET -v $Version $Community $Host "IF-MIB::${ifOut}"."$Interface" ` to_debug time is $Time, $SNMPGET check result in is $_result_in, out is $_result_out _result_in=`echo $_result_in |awk '{print $4}'` _result_out=`echo $_result_out|awk '{print $4}'` to_debug time is $Time, $SNMPGET check result in is $_result_in, out is $_result_out if [ -z "$_result_in" -o -z "$_result_out" ] ; then $Echo "No Data been get here. Please confirm your ARGS and re-check it with Verbose mode, then to check the log.(If you snmp not support 64 bit counter, do not use -6 option)" exit 3 fi In=`echo "$_result_in * 8 " |bc` Out=`echo "$_result_out * 8 " |bc` to_debug Index is $index Time is $Time, In is $In, Out is $Out HistData=`cat $CF_HIST_DATA| head -n 1` HistTime=`echo $HistData| awk -F "|" '{print $1}'|sed 's/ //g'` HistIn=`echo $HistData| awk -F "|" '{print $2}'|sed 's/ //g'` HistOut=`echo $HistData| awk -F "|" '{print $3}'|sed 's/ //g'` to_debug HistData is $HistData HistTime is $HistTime, HistIn is $HistIn, HistOut is $HistOut if [ -z "$HistTime" -o -z "$HistIn" -o -z "$HistOut" ] ; then if [ "$IsFirst" = "True" ]; then echo "$Time|$In|$Out" > $CF_HIST_DATA to_debug "$Time|$In|$Out" $CF_HIST_DATA continue else Severity="3" Msg="Unknown" OutPut="Can not found data in the history data file. \ Please to check the file $CF_HIST_DATA, or use use verbose mode and check the debug file" $Echo "$Msg" "-" $OutPut exit $Severity fi else Interval=`echo "$Time - $HistTime" | bc` if [ $Interval -lt $Min_Interval ] ; then $Echo "The check interval must greater than $Min_Interval Seconds. But now it is $Interval. Please retry it later." exit 3 fi to_debug DEBUG here: data of $Host $Interface $ifName "$Time|$In|$Out" echo "$Time|$In|$Out" > $CF_HIST_DATA if [ $? -ne 0 ];then Severity=3 Msg="Unknown" OutPut="Write File $CF_HIST_DATA Error with user `id`." $Echo "$Msg" "-" $OutPut exit $Severity fi if [ $Interval -gt $Max_Interval ] ; then $Echo "The check interval is too large(It is greater than $Max_Interval). The result is droped. We will use the fresh data at the next time." exit 3 fi fi DiffIn=`echo "$In - $HistIn" | bc` DiffOut=`echo "$Out - $HistOut" | bc` to_debug Interval/DiffIn/DiffOut $Interval $DiffIn $DiffOut if [ ` echo " $Interval > 0 " |bc ` -eq 0 ] ; then $Echo "we got a negative time interval value here." exit 3 fi if [ ` echo " $DiffOut >= 0 " |bc ` -eq 0 -o ` echo " $DiffIn >= 0 " |bc ` -eq 0 ] ; then $Echo "Maybe 32 bit counter overflow, because we got a negative value here." exit 3 fi bpsIn=`echo "$DiffIn / $Interval" | bc` bpsOut=`echo "$DiffOut / $Interval" | bc` to_debug bpsIn/bpsOut $bpsIn $bpsOut if [ $TrafficJitter"AA" = "TrueAA" ]; then if [ $C -lt $Num ]; then to_debug we have not the enough data to calculating. RI[$C]=$bpsIn RO[$C]=$bpsOut to_debug C $C C=`expr $C + 1` echo $C >$STAT_HIST_DATA echo ${RI[@]} >>$STAT_HIST_DATA echo ${RO[@]} >>$STAT_HIST_DATA isNotEnough=True continue else to_debug we have the enough data to calculating. RIAVG=0 ROAVG=0 lenRI=${#RI[@]} to_debug lenRI is $lenRI rii=0 while [ $rii -lt $lenRI ] do to_debug hist: rii $rii to_debug hist: rii RI[rii] $rii ${RI[$rii]} to_debug hist: rii RO[rii] $rii ${RO[$rii]} RIAVG=`echo "scale=$Scale; $RIAVG + ${RI[$rii]} " |bc` ROAVG=`echo "scale=$Scale; $ROAVG + ${RO[$rii]} " |bc` let rii++ to_debug RIAVG $RIAVG to_debug ROAVG $ROAVG done to_debug RIAVG $RIAVG to_debug ROAVG $ROAVG RIAVG=`echo "scale=$Scale; $RIAVG / $Num " |bc` ROAVG=`echo "scale=$Scale; $ROAVG / $Num " |bc` to_debug RIAVG $RIAVG to_debug ROAVG $ROAVG rii=0 while [ $rii -lt `expr $lenRI - 1` ] do RI[$rii]=${RI[`expr $rii + 1`]} RO[$rii]=${RO[`expr $rii + 1`]} to_debug new: rii RI[rii] $rii ${RI[`expr $rii + 1 `]} to_debug new: rii RO[rii] $rii ${RO[`expr $rii + 1 `]} let rii++ done RI[$rii]=$bpsIn RO[$rii]=$bpsOut echo $C >$STAT_HIST_DATA echo ${RI[@]} >>$STAT_HIST_DATA echo ${RO[@]} >>$STAT_HIST_DATA
DiffRIAVG=`echo "scale=$Scale; $bpsIn - $RIAVG" |bc` DiffROAVG=`echo "scale=$Scale; $bpsOut - $ROAVG" |bc` to_debug DiffRIAVG $DiffRIAVG to_debug DiffROAVG $DiffROAVG DiffRIAVG=`echo $DiffRIAVG | sed 's/-//'` DiffROAVG=`echo $DiffROAVG | sed 's/-//'` to_debug DiffRIAVG $DiffRIAVG to_debug DiffROAVG $DiffROAVG DiffRIAVG=`echo "scale=$Scale; $DiffRIAVG / $RIAVG * 100 " |bc` DiffROAVG=`echo "scale=$Scale; $DiffROAVG / $ROAVG * 100" |bc` DiffAVGTotal=`echo "scale=$Scale; $DiffRIAVG + $DiffROAVG" |bc` to_debug DiffRIAVG $DiffRIAVG to_debug DiffROAVG $DiffROAVG to_debug DiffAVGTotal $DiffAVGTotal fi ctDiffRIAVG=`echo "scale=$Scale; $ctDiffRIAVG + $DiffRIAVG" |bc` ctDiffROAVG=`echo "scale=$Scale; $ctDiffROAVG + $DiffROAVG" |bc` to_debug ctDiffRIAVG $ctDiffRIAVG to_debug ctDiffROAVG $ctDiffROAVG else ctbpsIn=`echo $ctbpsIn + $bpsIn|bc` ctbpsOut=`echo $ctbpsOut + $bpsOut|bc` fi
done
if [ "$isNotEnough" = "True" ]; then $Echo "OK - There was only `echo $C -1 |bc` hist data before this check. We need the $Num hist data to use for calculating. Please wait." exit 0 fi if [ "$IsFirst" = "True" ]; then Severity="0" Msg="OK" OutPut="It is the first time of this plugins to run, or some data file lost. We will get the data from the next time." $Echo "$Msg" "-" $OutPut exit $Severity fi
DiffRIAVG=`echo "scale=$Scale; $ctDiffRIAVG / $mmIntCnt" |bc` DiffROAVG=`echo "scale=$Scale; $ctDiffROAVG / $mmIntCnt" |bc` DiffAVGTotal=`echo "scale=$Scale; $DiffRIAVG + $DiffROAVG" |bc` to_debug DRIA $DiffRIAVG DROA $DiffROAVG DAVGT $DiffAVGTotal
else
if [ -z "$Version" -o -z "$Host" ] ; then $Echo "Args Error." print_full_help_msg exit 3 fi if [ "$SnmpVersion" = "3" ]; then if [ -z "$AuthString" ]; then $Echo "Args Error." print_full_help_msg exit 3 else Community="$AuthString" fi else if [ -z "$Community" ]; then $Echo "Args Error." print_full_help_msg exit 3 else Community=" -c $Community" fi fi if [ "$UseIntName""ZZ" == "TrueZZ" ]; then get_interface_index $InterfaceName Interface=$intIndex if [ -z "$Interface" -o "$Interface" == " " ] ; then $Echo Can not get the interface index with "$InterfaceName" at "$Host". exit 3 fi Interface=$(echo $Interface|sed 's/ /,/g') fi
if [ "$ListInt" = "True" ]; then $Echo "List Interface for host $Host." list_interface exit 3 fi if [ -z "$Interface" -o -z "$WarningV" -o -z "$CriticalV" ] ; then $Echo "Args Error." print_full_help_msg exit 3 fi to_debug All Values are \" Warning: "$WarningV" and Critical: "$CriticalV" \". WVC=`check_record_cnt "," "$WarningV"` CVC=`check_record_cnt "," "$CriticalV"` to_debug WVC is $WVC and CVC is $CVC if [ $UseRange = "True" ] ;then to_debug UseRange is True if [ $WVC -ne 2 -o $CVC -ne 2 ] ; then $Echo "Warning and Critical Value error." print_full_help_msg exit 3 else W1=`echo $WarningV| awk -F "," '{print $1}'` W1b=`echo $W1| awk -F "-" '{print $1}'` W1e=`echo $W1| awk -F "-" '{print $2}'` W2=`echo $WarningV| awk -F "," '{print $2}'` W2b=`echo $W2| awk -F "-" '{print $1}'` W2e=`echo $W2| awk -F "-" '{print $2}'` Wtb=`echo "$W1b + $W2b"|bc` Wte=`echo "$W1e + $W2e"|bc` to_debug Warning Value is $W1 $W2 $Wtb $Wte C1=`echo $CriticalV| awk -F "," '{print $1}'` C1b=`echo $C1| awk -F "-" '{print $1}'` C1e=`echo $C1| awk -F "-" '{print $2}'` C2=`echo $CriticalV| awk -F "," '{print $2}'` C2b=`echo $C2| awk -F "-" '{print $1}'` C2e=`echo $C2| awk -F "-" '{print $2}'` Ctb=`echo "$C1b + $C2b"|bc` Cte=`echo "$C1e + $C2e"|bc` to_debug Critical Value is $C1 $C2 $Ctb $Cte check_1b=`echo "$C1b < $W1b" | bc` check_1e=`echo "$C1e > $W1e" | bc` check_2b=`echo "$C2b < $W2b" | bc` check_2e=`echo "$C2e > $W2e" | bc` to_debug check_1 is $check_1b , $check_1e check_2 is $check_2b $check_2e if [ $check_1b -ne 1 -o $check_1e -ne 1 -o $check_2b -ne 1 -o $check_2e -ne 1 ] ; then $Echo "Error, the corresponding Critical End value must greater than Warning End value, And Critical Begin value must less than Warning End value" print_full_help_msg exit 3 fi fi else to_debug Use Range is False if [ $WVC -ne 2 -o $CVC -ne 2 ] ; then $Echo "Warning and Critical Value error." print_full_help_msg exit 3 else W1=`echo $WarningV| awk -F "," '{print $1}'` W2=`echo $WarningV| awk -F "," '{print $2}'` Wt=`echo "$W1 + $W2"|bc` to_debug Warning Value is $W1 $W2 $Wt C1=`echo $CriticalV| awk -F "," '{print $1}'` C2=`echo $CriticalV| awk -F "," '{print $2}'` Ct=`echo "$C1 + $C2"|bc` to_debug Critical Value is $C1 $C2 $Ct check_1=`echo "$C1 > $W1" | bc` check_2=`echo "$C2 > $W2" | bc` to_debug check_1 is $check_1 , check_2 is $check_2 if [ $check_1 -ne 1 -o $check_2 -ne 1 ] ; then $Echo "Error, the corresponding Critical value must greater than Warning value." print_full_help_msg exit 3 fi fi fi if [ -z $Suffix ]; then Suffix=itnms fi if [ $TrafficJitter"AA" = "TrueAA" ]; then Suffix=${Suffix}J fi if [ $UseRange = "True" ] ;then Suffix=${Suffix}R fi IntCnt=`check_record_cnt "," "$Interface"` to_debug Interface count $IntCnt if [ $IntCnt -gt 1 ];then isSMInt="True" fi to_debug isSMInt is $isSMInt declare -a SMArray Columns=24 Rows=$IntCnt Interface=`echo $Interface|sed 's/,/ /g'` SMInterfaces=($Interface) for ii in `seq 1 $IntCnt` do let "rIndex = $ii - 1" let "index = $rIndex * $Columns + 0" SMArray[$index]=${SMInterfaces[$rIndex]} to_debug SMArray ifIndex "${SMArray[$index]}" if [ "$isSMInt" = "True" ];then CF_HIST_DATA="/var/tmp/check_traffic_${Host}_${SMArray[$index]}_SM_${Username}_${Suffix}.hist_dat" else CF_HIST_DATA="/var/tmp/check_traffic_${Host}_${SMArray[$index]}_${Username}_${Suffix}.hist_dat" fi to_debug CF_HIST_DATA "$CF_HIST_DATA" let "index = $rIndex * $Columns + 1" SMArray[$index]=$CF_HIST_DATA to_debug SMArray CF_HIST_DATA "${SMArray[$index]}" done to_debug SMArray[@] ${SMArray[@]} Time=`date +%s` for ii in `seq 1 $IntCnt` do let "rIndex = $ii - 1" let "index = $rIndex * $Columns + 0" ifName="`$SNMPGET -v $Version $Community $Host IF-MIB::ifDescr.${SMArray[$index]}| awk -F ":" '{print $4}'`" ifSpeed="`$SNMPGET -v $Version $Community $Host IF-MIB::ifSpeed.${SMArray[$index]}| awk -F ":" '{print $4}'`" to_debug ifIndex ${SMArray[$index]}
Flag64ContentSM=`$SNMPGET -v $Version $Community $Host IF-MIB::ifHCOutOctets.${SMArray[$index]} 2>&1` if [ $? -eq 0 ]; then echo $Flag64ContentSM |grep Counter64 >/dev/null 2>&1 Flag64=$? if [ $Flag64 -eq 0 -a "$Version" = "2c" ];then ifIn=$ifIn64 ifOut=$ifOut64 BitSuffix=64 fi else ifIn=$ifIn32 ifOut=$ifOut32 BitSuffix=32 if [ "$Bit64" = "True" ] ;then $Echo "Maybe your Host(device) not support 64 bit counter. Please confirm your ARGS and re-check it with Verbose mode, then to check the log.(If you snmp not support 64 bit counter, do not use -6 option)" exit 3 fi fi let "index = $rIndex * $Columns + 1" to_debug CF_HIST_DATA ${SMArray[$index]} let "index = $rIndex * $Columns + 2" SMArray[$index]=${ifName} to_debug ifName ${SMArray[$index]} let "index = $rIndex * $Columns + 3" SMArray[$index]=${ifSpeed} to_debug ifSpeed ${SMArray[$index]} done to_debug SMArray[@] ${SMArray[@]} for ii in `seq 1 $IntCnt` do let "rIndex = $ii - 1" let "index = $rIndex * $Columns + 1" CF_HIST_DATA=${SMArray[$index]}_${BitSuffix} SMArray[$index]=$CF_HIST_DATA to_debug CF_HIST_DATA ${SMArray[$index]} let "index = $rIndex * $Columns + 4" STAT_HIST_DATA=${CF_HIST_DATA}_ctj_$Num SMArray[$index]=$STAT_HIST_DATA to_debug STAT_HIST_DATA ${SMArray[$index]} done for ii in `seq 1 $IntCnt` do let "rIndex = $ii - 1" let "index = $rIndex * $Columns + 1" CF_HIST_DATA=${SMArray[$index]} to_debug CF_HIST_DATA ${SMArray[$index]} if [ ! -f $CF_HIST_DATA ]; then IsFirst="True" touch $CF_HIST_DATA if [ $? -ne 0 ];then Severity=3 Msg="Unknown" OutPut="Create File $CF_HIST_DATA Error with user `id`." $Echo "$Msg" "-" $OutPut exit $Severity fi fi if [ ! -r $CF_HIST_DATA -o ! -w $CF_HIST_DATA ]; then Severity=3 Msg="Unknown" OutPut="Read or Write File $CF_HIST_DATA Error with user `id`." $Echo "$Msg" "-" $OutPut exit $Severity fi done if [ $TrafficJitter"AA" = "TrueAA" ]; then for ii in `seq 1 $IntCnt` do let "rIndex = $ii - 1" let "index = $rIndex * $Columns + 4" STAT_HIST_DATA=${SMArray[$index]} to_debug STAT_HIST_DATA ${SMArray[$index]} if [ ! -f $STAT_HIST_DATA ]; then touch $STAT_HIST_DATA IsStatFirst="True" if [ $? -ne 0 ];then Severity=3 Msg="Unknown" OutPut="Create File $STAT_HIST_DATA Error with user `id`." $Echo "$Msg" "-" $OutPut exit $Severity fi if [ ! -r $STAT_HIST_DATA -o ! -w $STAT_HIST_DATA ]; then Severity=3 Msg="Unknown" OutPut="Read or Write File $STAT_HIST_DATA Error with user `id`." $Echo "$Msg" "-" $OutPut exit $Severity fi gen_string $Num to_debug string_t $string_t TC=0 TRI=($string_t) TRO=($string_t) echo $TC >$STAT_HIST_DATA echo ${TRI[@]} >>$STAT_HIST_DATA echo ${TRO[@]} >>$STAT_HIST_DATA fi C=(`head -n 1 $STAT_HIST_DATA`) RI=(`head -n 2 $STAT_HIST_DATA|tail -n 1 `) RO=(`tail -n 1 $STAT_HIST_DATA`) to_debug C RI RO $C $RI $RO to_debug C RI RO $C ${RI[@]} ${RO[@]} to_debug C N $C $Num let "index = $rIndex * $Columns + 16" SMArray[$index]=${Num} to_debug Num ${SMArray[$index]} let "index = $rIndex * $Columns + 17" SMArray[$index]=${C} to_debug C ${SMArray[$index]} let "index = $rIndex * $Columns + 18" SMArray[$index]=${RI[@]} to_debug RI ${SMArray[$index]} let "index = $rIndex * $Columns + 19" SMArray[$index]=${RO[@]} to_debug RO ${SMArray[$index]} done fi for ii in `seq 1 $IntCnt` do let "rIndex = $ii - 1" let "index = $rIndex * $Columns + 0" curIfIdx=${SMArray[$index]} to_debug curIfIdx $curIfIdx let "index = $rIndex * $Columns + 2" curIfName=${SMArray[$index]} to_debug curIfName $curIfName _result_status=`$SNMPGET -v $Version $Community $Host "IF-MIB::ifOperStatus.${curIfIdx}"| awk '{print $4}' | awk -F '(' '{print $1}'` if [ "$_result_status" != "up" ]; then $Echo "The Interface name:${curIfName} -- index:${curIfIdx} you checked seems not up." exit 3 fi done ctbpsIn=0 ctbpsOut=0 ctDiffRIAVG=0 ctDiffROAVG=0 for ii in `seq 1 $IntCnt` do let "rIndex = $ii - 1" let "index = $rIndex * $Columns + 0" curIfIdx=${SMArray[$index]} to_debug curIfIdx $curIfIdx _result_in=`$SNMPGET -v $Version $Community $Host "IF-MIB::${ifIn}"."$curIfIdx"` _result_out=`$SNMPGET -v $Version $Community $Host "IF-MIB::${ifOut}"."$curIfIdx" ` to_debug time is $Time, $SNMPGET check result in is $_result_in, out is $_result_out _result_in=`echo $_result_in |awk '{print $4}'` _result_out=`echo $_result_out|awk '{print $4}'` to_debug time is $Time, $SNMPGET check result in is $_result_in, out is $_result_out if [ -z "$_result_in" -o -z "$_result_out" ] ; then $Echo "No Data been get here. Please confirm your ARGS and re-check it with Verbose mode, then to check the log.(If you snmp not support 64 bit counter, do not use -6 option)" exit 3 fi In=`echo "$_result_in * 8 " |bc` Out=`echo "$_result_out * 8 " |bc` to_debug Index is $index Time is $Time, In is $In, Out is $Out let "index = $rIndex * $Columns + 5" SMArray[$index]=$Time to_debug time is ${SMArray[$index]} let "index = $rIndex * $Columns + 6" SMArray[$index]=$In to_debug In is ${SMArray[$index]} let "index = $rIndex * $Columns + 7" SMArray[$index]=$Out to_debug Out is ${SMArray[$index]} let "index = $rIndex * $Columns + 1" curCHD=${SMArray[$index]} to_debug curCHD $curCHD HistData=`cat $curCHD| head -n 1` HistTime=`echo $HistData| awk -F "|" '{print $1}'|sed 's/ //g'` HistIn=`echo $HistData| awk -F "|" '{print $2}'|sed 's/ //g'` HistOut=`echo $HistData| awk -F "|" '{print $3}'|sed 's/ //g'` to_debug HistData is $HistData HistTime is $HistTime, HistIn is $HistIn, HistOut is $HistOut if [ -z "$HistTime" -o -z "$HistIn" -o -z "$HistOut" ] ; then if [ "$IsFirst" = "True" ]; then echo "$Time|$In|$Out" > $curCHD to_debug "$Time|$In|$Out" $curCHD continue else Severity="3" Msg="Unknown" OutPut="Can not found data in the history data file. \ Please to check the file $curCHD, or use use verbose mode and check the debug file" $Echo "$Msg" "-" $OutPut exit $Severity fi else let "index = $rIndex * $Columns + 8" SMArray[$index]=$HistTime to_debug HistTime is ${SMArray[$index]} let "index = $rIndex * $Columns + 9" SMArray[$index]=$HistIn to_debug HistIn is ${SMArray[$index]} let "index = $rIndex * $Columns + 10" SMArray[$index]=$HistOut to_debug HistOut is ${SMArray[$index]} Interval=`echo "$Time - $HistTime" | bc` if [ $Interval -lt $Min_Interval ] ; then $Echo "The check interval must greater than $Min_Interval Seconds. But now it s $Interval. Please retry it later." exit 3 fi to_debug DEBUG here: data of $Host $Interface $ifName "$Time|$In|$Out" echo "$Time|$In|$Out" > $curCHD if [ $? -ne 0 ];then Severity=3 Msg="Unknown" OutPut="Write File $curCHD Error with user `id`." $Echo "$Msg" "-" $OutPut exit $Severity fi if [ $Interval -gt $Max_Interval ] ; then $Echo "The check interval is too large(It is greater than $Max_Interval). The result is droped. We will use the fresh data at the next time." exit 3 fi fi DiffIn=`echo "$In - $HistIn" | bc` DiffOut=`echo "$Out - $HistOut" | bc` to_debug Interval/DiffIn/DiffOut $Interval $DiffIn $DiffOut if [ ` echo " $Interval > 0 " |bc ` -eq 0 ] ; then $Echo "we got a negative time interval value here." exit 3 fi if [ ` echo " $DiffOut >= 0 " |bc ` -eq 0 -o ` echo " $DiffIn >= 0 " |bc ` -eq 0 ] ; then $Echo "Maybe 32 bit counter overflow, because we got a negative value here." exit 3 fi bpsIn=`echo "$DiffIn / $Interval" | bc` bpsOut=`echo "$DiffOut / $Interval" | bc` to_debug bpsIn/bpsOut $bpsIn $bpsOut let "index = $rIndex * $Columns + 11" SMArray[$index]=$Interval to_debug Interval is ${SMArray[$index]} let "index = $rIndex * $Columns + 12" SMArray[$index]=$DiffIn to_debug DiffIn is ${SMArray[$index]} let "index = $rIndex * $Columns + 13" SMArray[$index]=$DiffOut to_debug DiffOut is ${SMArray[$index]} let "index = $rIndex * $Columns + 14" SMArray[$index]=$bpsIn to_debug bpsIn is ${SMArray[$index]} let "index = $rIndex * $Columns + 15" SMArray[$index]=$bpsOut to_debug bpsOut is ${SMArray[$index]} if [ $TrafficJitter"AA" = "TrueAA" ]; then let "index = $rIndex * $Columns + 4" curSHD=${SMArray[$index]} to_debug curSHD $curSHD let "index = $rIndex * $Columns + 16" curNum=${SMArray[$index]} to_debug curNum $curNum let "index = $rIndex * $Columns + 17" curC=${SMArray[$index]} to_debug curC $curC let "index = $rIndex * $Columns + 18" curRI=${SMArray[$index]} to_debug curRI $curRI let "index = $rIndex * $Columns + 19" curRO=${SMArray[$index]} to_debug curRO $curRO curRI=($curRI) curRO=($curRO) if [ $curC -lt $curNum ]; then to_debug we have not the enough data to calculating. curRI[$curC]=$bpsIn curRO[$curC]=$bpsOut to_debug curC $curC to_debug curRI ${curRI[@]} to_debug curRO ${curRO[@]} curC=`expr $curC + 1` echo $curC >$curSHD echo ${curRI[@]} >>$curSHD echo ${curRO[@]} >>$curSHD isNotEnough=True continue else to_debug we have the enough data to calculating. RIAVG=0 ROAVG=0 lencurRI=${#curRI[@]} to_debug lencurRI is $lencurRI rii=0 while [ $rii -lt $lencurRI ] do to_debug hist: rii $rii to_debug hist: rii curRI[rii] $rii ${curRI[$rii]} to_debug hist: rii curRO[rii] $rii ${curRO[$rii]} RIAVG=`echo "scale=$Scale; $RIAVG + ${curRI[$rii]} " |bc` ROAVG=`echo "scale=$Scale; $ROAVG + ${curRO[$rii]} " |bc` let rii++ to_debug RIAVG $RIAVG to_debug ROAVG $ROAVG done to_debug RIAVG $RIAVG to_debug ROAVG $ROAVG RIAVG=`echo "scale=$Scale; $RIAVG / $curNum " |bc` ROAVG=`echo "scale=$Scale; $ROAVG / $curNum " |bc` to_debug RIAVG $RIAVG to_debug ROAVG $ROAVG rii=0 while [ $rii -lt `expr $lencurRI - 1` ] do curRI[$rii]=${curRI[`expr $rii + 1`]} curRO[$rii]=${curRO[`expr $rii + 1`]} to_debug new: rii curRI[rii] $rii ${curRI[`expr $rii + 1 `]} to_debug new: rii curRO[rii] $rii ${curRO[`expr $rii + 1 `]} let rii++ done curRI[$rii]=$bpsIn curRO[$rii]=$bpsOut echo $curC >$curSHD echo ${curRI[@]} >>$curSHD echo ${curRO[@]} >>$curSHD to_debug new: all ${curRI[@]} to_debug new: all ${curRO[@]} DiffRIAVG=`echo "scale=$Scale; $bpsIn - $RIAVG" |bc` DiffROAVG=`echo "scale=$Scale; $bpsOut - $ROAVG" |bc` to_debug DiffRIAVG $DiffRIAVG to_debug DiffROAVG $DiffROAVG DiffRIAVG=`echo $DiffRIAVG | sed 's/-//'` DiffROAVG=`echo $DiffROAVG | sed 's/-//'` to_debug DiffRIAVG $DiffRIAVG to_debug DiffROAVG $DiffROAVG DiffRIAVG=`echo "scale=$Scale; $DiffRIAVG / $RIAVG * 100 " |bc` DiffROAVG=`echo "scale=$Scale; $DiffROAVG / $ROAVG * 100" |bc` DiffAVGTotal=`echo "scale=$Scale; $DiffRIAVG + $DiffROAVG" |bc` to_debug DiffRIAVG $DiffRIAVG to_debug DiffROAVG $DiffROAVG to_debug DiffAVGTotal $DiffAVGTotal fi ctDiffRIAVG=`echo "scale=$Scale; $ctDiffRIAVG + $DiffRIAVG" |bc` ctDiffROAVG=`echo "scale=$Scale; $ctDiffROAVG + $DiffROAVG" |bc` to_debug ctDiffRIAVG $ctDiffRIAVG to_debug ctDiffROAVG $ctDiffROAVG else ctbpsIn=`echo $ctbpsIn + $bpsIn|bc` ctbpsOut=`echo $ctbpsOut + $bpsOut|bc` fi
done
if [ "$isNotEnough" = "True" ]; then $Echo "OK - There was only `echo $curC -1 |bc` hist data before this check. We need the $curNum hist data to use for calculating. Please wait." exit 0 fi if [ "$IsFirst" = "True" ]; then Severity="0" Msg="OK" OutPut="It is the first time of this plugins to run, or some data file lost. We will get the data from the next time." $Echo "$Msg" "-" $OutPut exit $Severity fi
DiffRIAVG=`echo "scale=$Scale; $ctDiffRIAVG / $IntCnt" |bc` DiffROAVG=`echo "scale=$Scale; $ctDiffROAVG / $IntCnt" |bc` DiffAVGTotal=`echo "scale=$Scale; $DiffRIAVG + $DiffROAVG" |bc` to_debug DRIA $DiffRIAVG DROA $DiffROAVG DAVGT $DiffAVGTotal
fi
uIn=`echo "$ctbpsIn / 1000" | bc` uOut=`echo "$ctbpsOut / 1000" | bc`
if [ "$isM" = "True" ]; then uIn=`echo "scale=$Scale; $uIn / 1000" | bc` uOut=`echo "scale=$Scale; $uOut / 1000" | bc` fi
if [ "$isB" = "True" ]; then uIn=`echo "scale=$Scale; $uIn / 8 * (1000 / 1024)" | bc` uOut=`echo "scale=$Scale; $uOut / 8 * (1000 / 1024)" | bc` if [ "$isM" = "True" ]; then uIn=`echo "scale=$Scale; $uIn / 8 * (1000 / 1024 ) " | bc` uOut=`echo "scale=$Scale; $uOut / 8 * (1000 / 1024)" | bc` fi
fi
to_debug Unit_1 is $Unit_1, Unit_2 is $Unit_2 to_debug Interval is $Interval, DiffIn is $DiffIn, DiffOut is $DiffOut, uIn is $uIn, uOut is $uOut
if [ $UseRange = "True" ] ;then
check_w1b=`echo "$uIn > $W1b" | bc` check_w1e=`echo "$uIn < $W1e" | bc`
check_w2b=`echo "$uOut > $W2b" | bc` check_w2e=`echo "$uOut < $W2e" | bc` to_debug check_w1 is $check_w1b $check_w1e , check_w2 is $check_w2b $check_w2e check_c1b=`echo "$uIn > $C1b" | bc` check_c1e=`echo "$uIn < $C1e" | bc`
check_c2b=`echo "$uOut > $C2b" | bc` check_c2e=`echo "$uOut < $C2e" | bc` to_debug check_c1 is $check_c1b $check_c1e, check_c2 is $check_c2b $check_c2e if [ $check_w1b -eq 1 -a $check_w1e -eq 1 -a $check_w2b -eq 1 -a $check_w2e -eq 1 ] ; then Severity="0"; Msg="OK"; to_debug Severity is $Severity , Msg is $Msg elif [ $check_c1b -eq 1 -a $check_c1e -eq 1 -a $check_c2b -eq 1 -a $check_c2e -eq 1 ] ; then Severity="1"; Msg="Warning"; to_debug Severity is $Severity , Msg is $Msg else Severity="2"; Msg="Critical"; to_debug Severity is $Severity , Msg is $Msg fi elif [ $TrafficJitter"AA" = "TrueAA" ] ; then check_w1=`echo "$DiffRIAVG < $W1" | bc` check_w2=`echo "$DiffROAVG < $W2" | bc` to_debug check_w1 is $check_w1 , check_w2 is $check_w2 check_c1=`echo "$DiffRIAVG < $C1" | bc` check_c2=`echo "$DiffROAVG < $C2" | bc` to_debug check_c1 is $check_c1 , check_c2 is $check_c2 if [ $check_w1 -eq 1 -a $check_w2 -eq 1 ] ; then Severity="0"; Msg="OK"; to_debug Severity is $Severity , Msg is $Msg elif [ $check_c1 -eq 1 -a $check_c2 -eq 1 ] ; then Severity="1"; Msg="Warning"; to_debug Severity is $Severity , Msg is $Msg else Severity="2"; Msg="Critical"; to_debug Severity is $Severity , Msg is $Msg fi else check_w1=`echo "$uIn < $W1" | bc` check_w2=`echo "$uOut < $W2" | bc` to_debug check_w1 is $check_w1 , check_w2 is $check_w2 check_c1=`echo "$uIn < $C1" | bc` check_c2=`echo "$uOut < $C2" | bc` to_debug check_c1 is $check_c1 , check_c2 is $check_c2 if [ $check_w1 -eq 1 -a $check_w2 -eq 1 ] ; then Severity="0"; Msg="OK"; to_debug Severity is $Severity , Msg is $Msg elif [ $check_c1 -eq 1 -a $check_c2 -eq 1 ] ; then Severity="1"; Msg="Warning"; to_debug Severity is $Severity , Msg is $Msg else Severity="2"; Msg="Critical"; to_debug Severity is $Severity , Msg is $Msg fi
fi
uTotal=`echo "$uIn + $uOut" | bc` if [ `echo "$uIn < 1" | bc` -eq 1 ]; then uIn="0"${uIn} if [ "$uIn" = "00" ]; then uIn=0.0 fi fi
if [ `echo "$uOut < 1" | bc` -eq 1 ]; then uOut="0"${uOut} if [ "$uOut" = "00" ]; then uOut=0.0 fi fi
if [ `echo "$uTotal < 1" | bc` -eq 1 ]; then uTotal="0"${uTotal} if [ "$uTotal" = "00" ]; then uTotal=0.0 fi fi
to_debug Interval is $Interval, DiffIn is $DiffIn, DiffOut is $DiffOut, uIn is $uIn, uOut is $uOut, uTotal is $uTotal
if [ $UseRange = "True" ] ;then
if [ $Format"AA" = "SAA" ]; then $Echo "$Msg" "-" In/Out "$uIn"${Unit_1}${Unit_2}/"$uOut"${Unit_1}${Unit_2}\|In\=${uIn}${Unit_1}${Unit_2}\;\;\;0\;0 Out\=${uOut}${Unit_1}${Unit_2}\;\;\;0\;0 elif [ $Format"AA" = "sAA" ]; then $Echo "$Msg" "-" In/Out/Total/Interval "$uIn"${Unit_1}${Unit_2}/"$uOut"${Unit_1}${Unit_2}/"$uTotal"${Unit_1}${Unit_2}/"$Interval"s \|In\=${uIn}${Unit_1}${Unit_2}\;\;\;0\;0 Out\=${uOut}${Unit_1}${Unit_2}\;\;\;0\;0 Total\=${uTotal}${Unit_1}${Unit_2}\;\;\;0\;0 Interval\=${Interval}s\;1200\;1800\;0\;0 else $Echo "$Msg" "-" The Traffic In is "$uIn"${Unit_1}${Unit_2}, Out is "$uOut"${Unit_1}${Unit_2}, Total is "$uTotal"${Unit_1}${Unit_2}. The Check Interval is "$Interval"s \|In\=${uIn}${Unit_1}${Unit_2}\;\;\;0\;0 Out\=${uOut}${Unit_1}${Unit_2}\;\;\;0\;0 Total\=${uTotal}${Unit_1}${Unit_2}\;\;\;0\;0 Interval\=${Interval}s\;1200\;1800\;0\;0 fi exit $Severity
elif [ $TrafficJitter"AA" = "TrueAA" ]; then
if [ $Format"AA" = "SAA" ]; then $Echo "$Msg" "-" Traffic Jitter In/Out "$DiffRIAVG""%"/"$DiffROAVG""%"\|In\=$DiffRIAVG\;${W1}\;${C1}\;0\;0 Out\=$DiffROAVG\;${W2}\;${C2}\;0\;0 elif [ $Format"AA" = "sAA" ]; then $Echo "$Msg" "-" Traffic Jitter In/Out/Total/Interval "$DiffRIAVG""%"/"$DiffROAVG""%"/"$DiffAVGTotal""%"/"$Interval"s \|In\=$DiffRIAVG\;${W1}\;${C1}\;0\;0 Out\=$DiffROAVG\;${W2}\;${C2}\;0\;0 Total\=$DiffAVGTotal\;${Wt}\;${Ct}\;0\;0 Interval\=${Interval}s\;1200\;1800\;0\;0 else $Echo "$Msg" "-" The Traffic Jitter In is "$DiffRIAVG""%", Out is "$DiffROAVG""%", Total is "$DiffAVGTotal""%". The Check Interval is "$Interval"s \|In\=$DiffRIAVG\;${W1}\;${C1}\;0\;0 Out\=$DiffROAVG\;${W2}\;${C2}\;0\;0 Total\=$DiffAVGTotal\;${Wt}\;${Ct}\;0\;0 Interval\=${Interval}s\;1200\;1800\;0\;0 fi exit $Severity
else
if [ $Format"AA" = "SAA" ]; then $Echo "$Msg" "-" In/Out "$uIn"${Unit_1}${Unit_2}/"$uOut"${Unit_1}${Unit_2}\|In\=${uIn}${Unit_1}${Unit_2}\;${W1}\;${C1}\;0\;0 Out\=${uOut}${Unit_1}${Unit_2}\;${W2}\;${C2}\;0\;0 elif [ $Format"AA" = "sAA" ]; then $Echo "$Msg" "-" In/Out/Total/Interval "$uIn"${Unit_1}${Unit_2}/"$uOut"${Unit_1}${Unit_2}/"$uTotal"${Unit_1}${Unit_2}/"$Interval"s \|In\=${uIn}${Unit_1}${Unit_2}\;${W1}\;${C1}\;0\;0 Out\=${uOut}${Unit_1}${Unit_2}\;${W2}\;${C2}\;0\;0 Total\=${uTotal}${Unit_1}${Unit_2}\;${Wt}\;${Ct}\;0\;0 Interval\=${Interval}s\;1200\;1800\;0\;0 else $Echo "$Msg" "-" The Traffic In is "$uIn"${Unit_1}${Unit_2}, Out is "$uOut"${Unit_1}${Unit_2}, Total is "$uTotal"${Unit_1}${Unit_2}. The Check Interval is "$Interval"s \|In\=${uIn}${Unit_1}${Unit_2}\;${W1}\;${C1}\;0\;0 Out\=${uOut}${Unit_1}${Unit_2}\;${W2}\;${C2}\;0\;0 Total\=${uTotal}${Unit_1}${Unit_2}\;${Wt}\;${Ct}\;0\;0 Interval\=${Interval}s\;1200\;1800\;0\;0 fi exit $Severity fi
|