I am writing a collectd nagios custom check script in bash. The problem I am having is that nagios shows hostnames as host.name.domain but collectd holds WSP files as host_name_domain. My question is how can I make a variable convert the hostname that it gets from nagios (host.name.domain) to collectd format (host_name_domain).
This is the part where the convertion has to occur. So the WSP_PATH would give out collectd format of hostname in variable $NHOST
WSP_PATH=/var/lib/carbon/whisper/ctd/$NHOST/uptime/uptime.wsp
Bash has the required functionality built in (unless it's an ancient version):
Use sed:
As above, /g is required so that all instances of . are replaced with -
Although on second thoughts, it would probably make more sense to perform this (sed) operation on the $NHOST variable (now edited to show this)