Zabbix agent config » Historie » Version 1
Jeremias Keihsler, 13.01.2017 18:40
1 | 1 | Jeremias Keihsler | h1. Zabbix Agent Config |
---|---|---|---|
2 | |||
3 | h2. Userparameter |
||
4 | |||
5 | h3. Preliminary Note |
||
6 | |||
7 | Basically there is 2 ways to go the road. As the @Agentd@ is run with the @zabbix@ user |
||
8 | * you will have to give zabbix sudo-rights for the programs needed |
||
9 | * prepare via cron-jobs data for extraction which are accessible by the zabbix-user |
||
10 | Both solutions have their shortcomings: |
||
11 | * SUDO-Version |
||
12 | ** giving sudo-rights to zabbix might be considered a security risk |
||
13 | ** flooding logs with sudo-messages |
||
14 | ** you have to remove @requiretty@ to make sudo work with zabbix |
||
15 | * CRON-Version |
||
16 | ** if you cron-job doesn't deliver data, zabbix will reread old data over and over |
||
17 | ** the setup is more complex and not straight forward when it comes to debugging |
||
18 | |||
19 | h3. Sample UserParameter-List |
||
20 | |||
21 | <pre bash zabbix-agentd.conf> |
||
22 | #UserParameter=ipmi.temp.ambient,sudo ipmitool sdr type "Temperature" |grep Ambient |sed -e 's/.* | \([0-9]\+\).*/\1/' |
||
23 | #UserParameter=ipmi.fan.1,sudo ipmitool sdr | grep FAN1 |sed -e 's/.* | \([0-9]\+\).*/\1/' |
||
24 | #UserParameter=ipmi.fan.2,sudo ipmitool sdr | grep FAN2 |sed -e 's/.* | \([0-9]\+\).*/\1/' |
||
25 | #UserParameter=ipmi.fan.3,sudo ipmitool sdr | grep FAN3 |sed -e 's/.* | \([0-9]\+\).*/\1/' |
||
26 | #UserParameter=ipmi.fan.4,sudo ipmitool sdr | grep FAN4 |sed -e 's/.* | \([0-9]\+\).*/\1/' |
||
27 | UserParameter=system.smartd[*],cat /var/cache/myzabbix/smart.$1.status| grep $2| tail -1| cut -c 88-|cut -f1 -d' ' |
||
28 | UserParameter=system.smartd.value[*],cat /var/cache/myzabbix/smart.$1.status| grep $2| tail -1| cut -c 38-|cut -f1 -d' ' |
||
29 | UserParameter=system.smartd.worst[*],cat /var/cache/myzabbix/smart.$1.status| grep $2| tail -1| cut -c 44-|cut -f1 -d' ' |
||
30 | UserParameter=system.smartd.thres[*],cat /var/cache/myzabbix/smart.$1.status| grep $2| tail -1| cut -c 50-|cut -f1 -d' ' |
||
31 | #UserParameter=system.apcups[*],cat /var/cache/myzabbix/apcups.status| grep $1| tail -1|cut -c 12-|sed 's/^[ ]*//'|cut -f1 -d' ' |
||
32 | </pre> |
||
33 | |||
34 | h3. Sudo-Version |
||
35 | |||
36 | <pre><code class="bash"> |
||
37 | visudo |
||
38 | </code></pre> |
||
39 | <pre> |
||
40 | ... |
||
41 | # |
||
42 | # Disable "ssh hostname sudo <cmd>", because it will show the password in clear. |
||
43 | # You have to run "ssh -t hostname sudo <cmd>". |
||
44 | # |
||
45 | #JKE 2012-09-20 commented out to make zabbix-sudo work |
||
46 | #Defaults requiretty |
||
47 | ... |
||
48 | |||
49 | ... |
||
50 | ## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment) |
||
51 | #includedir /etc/sudoers.d |
||
52 | </pre> |
||
53 | <pre><code class="bash"> |
||
54 | visudo -f /etc/sudoers.d/zabbix |
||
55 | </code></pre> |
||
56 | <pre bash zabbix> |
||
57 | zabbix ALL = (ALL) NOPASSWD:/usr/bin/ipmitool |
||
58 | zabbix ALL = (ALL) NOPASSWD:/usr/sbin/smartctl |
||
59 | </pre> |
||
60 | |||
61 | h3. Cron-Version |
||
62 | |||
63 | create zabbix-data exchange-directory |
||
64 | <pre><code class="bash"> |
||
65 | mkdir /var/cache/myzabbix |
||
66 | </code></pre> |
||
67 | create zabbix-data-file |
||
68 | <pre><code class="bash"> |
||
69 | vim /usr/local/bin/smart_status.sh |
||
70 | </code></pre> |
||
71 | <pre bash smart_status.sh> |
||
72 | /usr/sbin/smartctl -A /dev/sda > /var/cache/myzabbix/smart.sda.status |
||
73 | /usr/sbin/smartctl -A /dev/sdb > /var/cache/myzabbix/smart.sdb.status |
||
74 | </pre> |
||
75 | <pre bash smart_status_megaraid.sh> |
||
76 | /usr/sbin/smartctl -d sat+megaraid,10 -a /dev/sda > /var/cache/myzabbix/smart.sda.0.status |
||
77 | /usr/sbin/smartctl -d sat+megaraid,11 -a /dev/sda > /var/cache/myzabbix/smart.sda.1.status |
||
78 | /usr/sbin/smartctl -d sat+megaraid,12 -a /dev/sdb > /var/cache/myzabbix/smart.sdb.0.status |
||
79 | /usr/sbin/smartctl -d sat+megaraid,13 -a /dev/sdc > /var/cache/myzabbix/smart.sdc.0.status |
||
80 | /usr/sbin/smartctl -d sat+megaraid,14 -a /dev/sdc > /var/cache/myzabbix/smart.sdc.1.status |
||
81 | </pre> |
||
82 | <pre><code class="bash"> |
||
83 | vim /usr/local/bin/apcups_status.sh |
||
84 | </code></pre> |
||
85 | <pre bash apcups_status.sh> |
||
86 | /etc/init.d/apcupsd status > /var/cache/myzabbix/apcups.status |
||
87 | </pre> |
||
88 | create cron-job |
||
89 | <pre><code class="bash"> |
||
90 | vim /etc/cron.d/zabbix |
||
91 | </code></pre> |
||
92 | <pre> |
||
93 | # JKE 2012-10-19 |
||
94 | # |
||
95 | # minute hour day month dayofweek |
||
96 | # m h d m d |
||
97 | # - - - - - |
||
98 | # | | | | | |
||
99 | # | | | | +-day of week (0-7) sunday=0 or 7 |
||
100 | # | | | +---month (1-12) |
||
101 | # | | +-----day of month (1-31) |
||
102 | # | +-------hour (0-23) |
||
103 | # +---------min (0-59) |
||
104 | # |
||
105 | # */2 * * * * root /usr/local/bin/apcups_status.sh |
||
106 | */5 * * * * root /usr/local/bin/smart_status.sh |
||
107 | 5 1 * * * root /usr/local/bin/zabbix-mysql-backupconf.sh |
||
108 | |||
109 | </pre> |