I want to collect data from the tool hdsentinel, which requires root access. How do i run this utility as root from telegraf, which is run by the user telegraf?
the script is like this: hdsentinel -solid | awk '{print "hdsentinel,disk=" $5 " health=" $3 ",temp="$2}' | grep -v "General"
running it as sudo -u telegraf gives an error 1.
how do i make it run correctly?
edit: i have edited sudoers with this, but did not help: telegraf ALL=(ALL) NOPASSWD: /etc/telegraf/hdstats
i am trying to run the script as telegraf user to check it’s correctness. i understand telegraf is running it as telegraf user as well. basically i need the script to be run by the telegraf user as root
my config is quite simple:
[[inputs.cpu]]
percpu = true
totalcpu = true
fielddrop = ["time_*"]
[[inputs.temp]]
# no configuration
[[inputs.disk]]
ignore_fs = ["tmpfs", "devtmpfs"]
[[inputs.kernel]]
# no configuration
# Read metrics about memory usage
[[inputs.mem]]
# no configuration
# Get the number of processes and group them by status
[[inputs.processes]]
# no configuration
# Read metrics about swap memory usage
[[inputs.swap]]
# no configuration
# Read metrics about system load & uptime
[[inputs.system]]
# no configuration
[[inputs.linux_sysctl_fs]]
# no configuration
[[inputs.ipmi_sensor]]
# If no servers are specified, the plugin will query the local machine sensor stats
servers = [ "ipmiuser:ipmiuser@lanplus(192.168.5.9)" ]
path = "ipmitool"
privilege = "USER"
interval = "10m"
metric_version = 2
[[inputs.exec]]
commands = ["/etc/telegraf/hdstats.sh"]
timeout = "5s"
interval = "120m"
data_format = "influx"
[[outputs.influxdb]]
# The full HTTP or UDP URL for your InfluxDB instance.
##
## Multiple URLs can be specified for a single cluster, only ONE of the
## urls will be written to each interval.
urls = ["http://192.168.50.8:8086"]
database = "hpserver"
## Timeout for HTTP messages.
timeout = "5s"
is still asking for a password (which the telegraf user does not have).
not sure how relevant is this, but my default user is root (this is a proxmox server), so su does not make sense in this scenario i think. i used sudo -u telegraf bash to become telegraf what was successully confirmed by whoami
the issue was with the general placement of data in the sudoers file. it seems in debian whatever is in the folder /etc/sudoers.d takes preference, so I had to add the NOPASSWD: declarations there. now it works as it should