1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006-2016 OpenWrt.org
8 COLLECTD_CONF
="/tmp/collectd.conf"
9 LOG
="logger -t collectd[$$] -p"
14 [ -d /usr
/libexec
/collectd
] && {
15 find /usr
/libexec
/collectd
! -perm 0500 -exec chmod 0500 '{}' '+'
16 find /usr
/libexec
/collectd
! \
( -user nobody
-a -group nogroup \
) -exec chown nobody
:nogroup
'{}' '+'
20 printf "<Plugin exec>\n" >> "$COLLECTD_CONF"
21 config_foreach process_exec_sections exec_input
"Exec"
22 config_foreach process_exec_sections exec_notify
"NotificationExec"
23 printf "</Plugin>\n\n" >> "$COLLECTD_CONF"
26 process_exec_sections
() {
30 local cmdline cmduser cmdgroup
32 config_get cmdline
"$cfg" cmdline
33 [ -z "$cmdline" ] && {
34 $LOG notice
"No cmdline option in config $cfg defined"
38 config_get cmduser
"$cfg" cmduser
39 [ -z "$cmduser" ] && {
40 $LOG notice
"No cmduser option in config $cfg defined"
44 config_get cmdgroup
"$cfg" cmdgroup
45 if [ -z "$cmdgroup" ]; then
46 printf "\\t%s \"%s\" \"%s\"\n" "${section}" "${cmduser}" "${cmdline}" >> "$COLLECTD_CONF"
48 printf "\\t%s \"%s:%s\" \"%s\"\n" "${section}" "${cmduser}" "${cmdgroup}" "${cmdline}" >> "$COLLECTD_CONF"
53 printf "<Plugin curl>\n" >> "$COLLECTD_CONF"
54 config_foreach process_curl_page curl_page
55 printf "</Plugin>\n\n" >> "$COLLECTD_CONF"
63 config_get name
"$cfg" name
65 $LOG notice
"No name option in config $cfg defined"
69 config_get url
"$cfg" url
71 $LOG notice
"No URL option in config $cfg defined"
75 printf "\\t<Page \"%s\">\n" "${name}" >> "$COLLECTD_CONF"
76 printf "\\t\\tURL \"%s\"\n" "${url}" >> "$COLLECTD_CONF"
77 printf "\\t\\tMeasureResponseTime true\n" >> "$COLLECTD_CONF"
78 printf "\\t</Page>\n" >> "$COLLECTD_CONF"
84 local TimeToLive Forward CacheFlush
86 printf "<Plugin network>\n" >> "$COLLECTD_CONF"
87 config_foreach process_network_sections network_listen
"listen"
88 config_foreach process_network_sections network_server
"server"
90 config_get TimeToLive
"$cfg" TimeToLive
91 [ -z "$TimeToLive" ] ||
{
92 printf "\\tTimeToLive %s\n" "${TimeToLive}" >> "$COLLECTD_CONF"
95 config_get CacheFlush
"$cfg" CacheFlush
96 [ -z "$CacheFlush" ] ||
{
97 printf "\\tCacheFlush %s\n" "${CacheFlush}" >> "$COLLECTD_CONF"
100 config_get_bool Forward
"$cfg" Forward
101 if [ "$value" = "0" ]; then
102 printf "\\tForward false\n" >> "$COLLECTD_CONF"
104 printf "\\tForward true\n" >> "$COLLECTD_CONF"
107 printf "</Plugin>\n\n" >> "$COLLECTD_CONF"
110 process_network_sections
() {
114 local host port output
116 config_get
host "$cfg" host
118 $LOG notice
"No host option in config $cfg defined"
122 if [ "$section" = "server" ]; then
123 output
="Server \"$host\""
125 output
="Listen \"$host\""
128 config_get port
"$cfg" port
129 if [ -z "$port" ]; then
130 printf "\\t%s\n" "${output}" >> "$COLLECTD_CONF"
132 printf "\\t%s \"%s\"\n" "${output}" "${port}" >> "$COLLECTD_CONF"
139 printf "<Plugin iptables>\n" >> "$COLLECTD_CONF"
140 config_foreach process_iptables_sections iptables_match
141 printf "</Plugin>\n\n" >> "$COLLECTD_CONF"
144 process_iptables_sections
() {
149 config_get table
"$cfg" table
151 $LOG notice
"No table option in config $cfg defined"
155 config_get chain
"$cfg" chain
157 $LOG notice
"No chain option in config $cfg defined"
161 config_get index
"$cfg" index
163 $LOG notice
"No index option in config $cfg defined"
167 config_get name
"$cfg" name
168 if [ -z "$name" ]; then
169 printf "\\tChain %s %s %s\n" "${table}" "${chain}" "${index}" >> "$COLLECTD_CONF"
171 printf "\\tChain %s %s %s \"%s\"\n" "${table}" "${chain}" "${index}" "${name}">> "$COLLECTD_CONF"
181 CONFIG_LIST
="${CONFIG_LIST}${indent}${option} \"$value\"\n"
191 .
/usr
/share
/libubox
/jshn.sh
193 json_load_file
"$json"
195 json_select string
1>/dev
/null
2>&1
196 if [ $?
-eq 0 ]; then
198 for key
in ${keys}; do
199 json_get_var option
"$key"
200 config_get value
"$cfg" "$option" ""
202 config
="${config}${indent}${option} \"${value}\"\n"
208 json_select bool
1>/dev
/null
2>&1
209 if [ $?
-eq 0 ]; then
211 for key
in ${keys}; do
212 json_get_var option
"$key"
213 config_get_bool value
"$cfg" "$option"
214 if [ "$value" = "0" ]; then
215 config
="${config}${indent}${option} false\n"
218 if [ "$value" = "1" ]; then
219 config
="${config}${indent}${option} true\n"
225 json_select list
1>/dev
/null
2>&1
226 if [ $?
-eq 0 ]; then
228 for key
in ${keys}; do
229 json_get_var option
"$key"
231 config_list_foreach
"$cfg" "$option" add_list_option
"$option" "$indent"
232 config
="${config}${CONFIG_LIST}"
237 [ -z "$config" ] ||
{
238 printf "%s<Plugin %s>\n" "${CONFIG_STRING}" "$cfg" >> "$COLLECTD_CONF"
239 echo -e "${config}" >> "$COLLECTD_CONF"
240 printf "%s</Plugin>\n" "${CONFIG_STRING}" >> "$COLLECTD_CONF"
243 printf "\n" >> "$COLLECTD_CONF"
249 local enable keys key option value
251 config_get
enable "$cfg" enable 0
252 [ "$enable" = "1" ] ||
return 0
254 [ -f "/usr/lib/collectd/$cfg.so" ] ||
{
255 $LOG notice
"Plugin collectd-mod-$cfg not installed"
259 [ -f "/usr/share/collectd/plugin/$cfg.json" ] ||
{
260 $LOG notice
"Configuration definition file for $cfg not found"
264 printf "LoadPlugin %s\n" "$cfg" >> "$COLLECTD_CONF"
276 process_network
"$cfg"
284 process_generic
"$cfg" "\\t" "/usr/share/collectd/plugin/$cfg.json"
290 local alt_config_file BaseDir Include PIDFile PluginDir TypesDB
291 local Interval ReadThreads Hostname
293 rm -f "$COLLECTD_CONF"
295 [ -f /etc
/config
/collectd
] ||
{
296 $LOG notice
"UCI config not found"
300 config_get alt_config_file globals alt_config_file
302 # If "alt_config_file" specified, use that instead
303 [ -n "$alt_config_file" ] && [ -f "$alt_config_file" ] && {
304 rm -f "$COLLECTD_CONF"
305 ln -s "$alt_config_file" "$COLLECTD_CONF"
310 config_get BaseDir globals BaseDir
"/var/run/collectd"
311 printf "BaseDir \"%s\"\n" "$BaseDir" >> "$COLLECTD_CONF"
313 config_get PIDFile globals PIDFile
"/var/run/collectd.pid"
314 printf "PIDFile \"%s\"\n" "$PIDFile" >> "$COLLECTD_CONF"
316 config_get PluginDir globals PluginDir
"/usr/lib/collectd"
317 printf "PluginDir \"%s\"\n" "$PluginDir" >> "$COLLECTD_CONF"
319 config_get TypesDB globals TypesDB
"/usr/share/collectd/types.db"
320 printf "TypesDB \"%s\"\n" "$TypesDB" >> "$COLLECTD_CONF"
322 config_get Interval globals Interval
30
323 printf "Interval %s\n" "$Interval" >> "$COLLECTD_CONF"
325 config_get ReadThreads globals ReadThreads
2
326 printf "ReadThreads \"%s\"\n" "$ReadThreads" >> "$COLLECTD_CONF"
328 config_get Hostname globals Hostname
"$(uname -n)"
329 printf "Hostname \"%s\"\n" "$Hostname" >> "$COLLECTD_CONF"
331 config_get Include globals Include
"/tmp/collectd.d"
332 printf "Include \"%s\"\n" "$Include" >> "$COLLECTD_CONF"
335 printf "\n" >> "$COLLECTD_CONF"
338 config_foreach process_plugins plugin
343 procd_add_reload_trigger
"collectd"
350 procd_set_param
command /usr
/sbin
/collectd
351 procd_append_param
command -C "$COLLECTD_CONF"
352 procd_append_param
command -f # don't daemonize
353 procd_set_param nice
"$NICEPRIO"
354 procd_set_param stderr
1
355 procd_set_param respawn