1.Установка скрипта на Zabbix-агенте
1 |
# megacli -LDInfo -LAll -a0 –NoLog |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
Adapter 0 -- Virtual Drive Information: Virtual Drive: 0 (Target Id: 0) Name : RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0 Size : 2.728 TB Sector Size : 512 Is VD emulated : Yes Mirror Data : 2.728 TB State : Optimal Strip Size : 256 KB Number Of Drives : 2 Span Depth : 1 Default Cache Policy: WriteBack, ReadAhead, Direct, Write Cache OK if Bad BBU Current Cache Policy: WriteBack, ReadAhead, Direct, Write Cache OK if Bad BBU Default Access Policy: Read/Write Current Access Policy: Read/Write Disk Cache Policy : Disk's Default Encryption Type : None Bad Blocks Exist: No Is VD Cached: No Exit Code: 0x00 |
1 |
# megacli -PDlist -a0 -NoLog |
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 |
Adapter #0 Enclosure Device ID: 252 Slot Number: 0 Drive's position: DiskGroup: 0, Span: 0, Arm: 0 Enclosure position: N/A Device Id: 3 WWN: 50014ee65b17627a Sequence Number: 2 Media Error Count: 0 Other Error Count: 0 Predictive Failure Count: 0 Last Predictive Failure Event Seq Number: 0 PD Type: SATA Raw Size: 2.728 TB [0x15d50a3b0 Sectors] Non Coerced Size: 2.728 TB [0x15d40a3b0 Sectors] Coerced Size: 2.728 TB [0x15d400000 Sectors] Sector Size: 0 Logical Sector Size: 0 Physical Sector Size: 0 Firmware state: Online, Spun Up Commissioned Spare : No Emergency Spare : No Device Firmware Level: 1K03 Shield Counter: 0 Successful diagnostics completion on : N/A SAS Address(0): 0x4433221103000000 Connected Port Number: 1(path0) Inquiry Data: WD-WMC1F0E62TV5WDC WD3000FYYZ-01UL1B2 01.01K03 FDE Capable: Not Capable FDE Enable: Disable Secured: Unsecured Locked: Unlocked Needs EKM Attention: No Foreign State: None Device Speed: 6.0Gb/s Link Speed: 6.0Gb/s Media Type: Hard Disk Device Drive: Not Certified Drive Temperature :41C (105.80 F) PI Eligibility: No Drive is formatted for PI information: No PI: No PI Drive's NCQ setting : N/A Port-0 : Port status: Active Port's Linkspeed: 6.0Gb/s Drive has flagged a S.M.A.R.T alert : No Enclosure Device ID: 252 Slot Number: 1 Drive's position: DiskGroup: 0, Span: 0, Arm: 1 Enclosure position: N/A Device Id: 2 WWN: 5000c500521a8d55 Sequence Number: 2 Media Error Count: 0 Other Error Count: 0 Predictive Failure Count: 0 Last Predictive Failure Event Seq Number: 0 PD Type: SATA Raw Size: 2.728 TB [0x15d50a3b0 Sectors] Non Coerced Size: 2.728 TB [0x15d40a3b0 Sectors] Coerced Size: 2.728 TB [0x15d400000 Sectors] Sector Size: 0 Logical Sector Size: 0 Physical Sector Size: 0 Firmware state: Online, Spun Up Commissioned Spare : No Emergency Spare : No Device Firmware Level: CC4B Shield Counter: 0 Successful diagnostics completion on : N/A SAS Address(0): 0x4433221102000000 Connected Port Number: 0(path0) Inquiry Data: S1F0YM5XST3000DM001-9YN166 CC4B FDE Capable: Not Capable FDE Enable: Disable Secured: Unsecured Locked: Unlocked Needs EKM Attention: No Foreign State: None Device Speed: 6.0Gb/s Link Speed: 6.0Gb/s Media Type: Hard Disk Device Drive: Not Certified Drive Temperature :39C (102.20 F) PI Eligibility: No Drive is formatted for PI information: No PI: No PI Drive's NCQ setting : N/A Port-0 : Port status: Active Port's Linkspeed: 6.0Gb/s Drive has flagged a S.M.A.R.T alert : No |
Узнаем расположение бинарника megacli
1 |
# which megacli |
1 |
/usr/sbin/megacli |
Если путь к бинарнику отличается,то изменяем его в скрипте и в файле /etc/sudoers
1 |
# nano /etc/zabbix/scripts/lsimegaraid.sh |
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 |
#!/bin/bash export LC_ALL="" export LANG="en_US.UTF-8" # MEGACLI="sudo /usr/sbin/megacli" # if [[ -n ${1} && -n ${2} && -z ${3} ]]; then ##### DISCOVERY ##### TYPE="${2}" if [[ ${TYPE} == "virtdiskovery" ]]; then DRIVES=`${MEGACLI} -LDInfo -LAll -a0 -NoLog | awk '/Virtual Drive:/ {printf("VirtualDrive%d\n", $3)}'` if [[ -n ${DRIVES} ]]; then JSON="{ \"data\":[" SEP="" for DRIVE in ${DRIVES}; do JSON=${JSON}"$SEP{\"{#VIRTNUM}\":\"${DRIVE}\"}" SEP=", " done JSON=${JSON}"]}" echo ${JSON} fi elif [[ ${TYPE} == "physdiskovery" ]]; then DRIVES=`${MEGACLI} -PDlist -a0 -NoLog | awk '/Slot Number:/ {printf("DriveSlot%d\n", $3)}'` if [[ -n ${DRIVES} ]]; then JSON="{ \"data\":[" SEP="" for DRIVE in ${DRIVES}; do JSON=${JSON}"$SEP{\"{#PHYSNUM}\":\"${DRIVE}\"}" SEP=", " done JSON=${JSON}"]}" echo ${JSON} fi fi exit 0 elif [[ -n ${1} && -n ${2} && -n ${3} ]]; then ##### PARAMETERS ##### ##### PARAMETERS ##### HOST="${1}" DRIVE="${2}" METRIC="${3}" FILECACHE="/tmp/zabbix.lsimegaraid.cache" TTLCACHE="55" TIMENOW=`date '+%s'` ##### CACHE ##### if [ -s "${FILECACHE}" ]; then TIMECACHE=`stat -c"%Y" "${FILECACHE}"` else TIMECACHE=0 fi if [ "$((${TIMENOW} - ${TIMECACHE}))" -gt "${TTLCACHE}" ]; then echo "" >> ${FILECACHE} # !!! DATACACHE=`${MEGACLI} -PDlist -a0 -NoLog | awk -F':' ' function ltrim(s) { sub(/^[ \t]+/, "", s); return s } function rtrim(s) { sub(/[ \t]+$/, "", s); return s } function trim(s) { return rtrim(ltrim(s)); } /Slot Number/ {slotcounter+=1; slot[slotcounter]=trim($2)} /Inquiry Data/ {inquiry[slotcounter]=trim($2)} /Firmware state/ {state[slotcounter]=trim($2)} /Drive Temperature/ {temperature[slotcounter]=trim($2)} /S.M.A.R.T/ {smart[slotcounter]=trim($2)} /Media Error Count/ {mediaerror[slotcounter]=trim($2)} /Other Error Count/ {othererror[slotcounter]=trim($2)} /Predictive Failure Count/ {failurecount[slotcounter]=trim($2)} END { for (i=1; i<=slotcounter; i+=1) { printf ( "DriveSlot%d inquiry:%s\n",slot[i], inquiry[i]); printf ( "DriveSlot%d state:%s\n", slot[i], state[i]); printf ( "DriveSlot%d temperature:%d\n", slot[i], temperature[i]); printf ( "DriveSlot%d smart:%s\n", slot[i], smart[i]); printf ( "DriveSlot%d mediaerror:%d\n", slot[i], mediaerror[i]); printf ( "DriveSlot%d othererror:%d\n", slot[i], othererror[i]); printf ( "DriveSlot%d failurecount:%d\n", slot[i], failurecount[i]); } }'; ${MEGACLI} -LDInfo -LAll -a0 -NoLog | awk -F':' ' function ltrim(s) { sub(/^[ \t]+/, "", s); return s } function rtrim(s) { sub(/[ \t]+$/, "", s); return s } function trim(s) { return rtrim(ltrim(s)); } /Virtual Drive:/ {drivecounter+=1; slot[drivecounter]=trim($2);} /State/ {state[drivecounter]=trim($2)} /Bad Blocks/ {badblock[drivecounter]=trim($2)} END { for (i=1; i<=drivecounter; i+=1) { printf ( "VirtualDrive%d state:%s\n", slot[i], state[i]); printf ( "VirtualDrive%d badblock:%s\n", slot[i], badblock[i]); } }'` || exit 1 echo "${DATACACHE}" > ${FILECACHE} # !!! fi # cat "${FILECACHE}" | grep -i ${DRIVE} | awk -F':' "/${METRIC}/ {print \$2}" | head -n1 exit 0 # else exit 0 fi |
Установка прав
1 |
# chown root:zabbix /etc/zabbix/scripts/lsimegaraid.sh |
1 |
# chmod 550 /etc/zabbix/scripts/lsimegaraid.sh |
2.Настройка прав пользователю zabbix в sudo
1 |
# visudo |
1 2 3 |
# zabbix ALL=(ALL) NOPASSWD: /usr/sbin/megacli -LDInfo -LAll -a0 -NoLog # zabbix ALL=(ALL) NOPASSWD: /usr/sbin/megacli -PDlist -a0 –NoLog zabbix ALL=(ALL) NOPASSWD: /usr/sbin/megacli |
Проверка работы скрипта для пользователя Zabbix
1 |
# sudo -u zabbix /etc/zabbix/scripts/lsimegaraid.sh none virtdiskovery |
1 |
# sudo -u zabbix /etc/zabbix/scripts/lsimegaraid.sh none physdiskovery |
1 |
# sudo -u zabbix /etc/zabbix/scripts/lsimegaraid.sh none VirtualDrive0 state |
3.Настройка Zabbix-агента
1 |
# nano /etc/zabbix/zabbix_agentd.d/userparameter_lsimegaraid.conf |
1 2 |
### LSI MegaRaid Monitoring UserParameter=lsimegaraid[*],/etc/zabbix/scripts/lsimegaraid.sh "none" $1 $2 |
1 |
# service zabbix-agent restart |
Проверка удаленно с Zabbix-сервера
1 |
# zabbix_get -s myservername -k "lsimegaraid[DriveSlot0, inquiry]" |
1 |
WD-WMC1F0E62TV5WDC WD3000FYYZ-01UL1B2 01.01K03 |
4.Настройка Zabbix-сервера
Скачиваем, распаковываем и импортируем шаблон
zabbix2-lsimegaraid-template.zip
Добавляем шаблон к хосту, на котором мониторим LSI Megaraid
Проверяем, что через 1-2 минуты на хосте появились Items с именем LSI Megaraid
Monitoring->Latest Data->фильтруем по требуемому хосту в поле Hosts-> LSI Megaraid
Источник:
http://wiki.enchtex.info/howto/zabbix/zabbix_megaraid_monitoring