Showing posts with label Freenas. Show all posts
Showing posts with label Freenas. Show all posts

Wednesday, October 21, 2020

Install Zabbix agent on TrueNAS

 In my previous article from 2018 I did mention how to install teh Zabbix agent on FreeNAS.

Since then two years are passed and FreeNAS has been replaced by TrueNAS provides the same functionality in a new version with a new name.

The steps for installation are remained the same, but you won't need to build the agent package yourself, you can use the packages provided from Zabbix for FreeBSD.

So lets see what you have to do now:

1. Download the binary package from the Zabbix webpage at https://www.zabbix.com/de/download_agents?version=4.0+LTS&release=4.0.25&os=FreeBSD&os_version=11.2&hardware=amd64&encryption=GnuTLS&packaging=Archive

It's no problem that FreeBSD 12.x is not listed, the 11.2 packages still work

2. Unpack the /bin and /sbin folders into /usr/local of your TrueNAS server

3. Unpack the /conf/* into /etc

4. Create a use and group zabbix so your agent wont run as root, you need to do this via GUI, otherwiese the account will be gone after reboot

5. Edit your /etc/zabbit_agentd:conf to match your needs

6. Enable daemon

echo 'zabbix_agentd_enable="YES"' >> /etc/rc.conf  
 
Create /etc/rc.d/zabbix_agentd:
#!/bin/sh

# PROVIDE: zabbix_agentd
# REQUIRE: DAEMON
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf to
# enable zabbix_agentd:
#
# zabbix_agentd_enable (bool): Set to NO by default.  Set it to YES to
#         enable zabbix_agentd.
#

. /etc/rc.subr

name="zabbix_agentd"
rcvar=zabbix_agentd_enable
start_precmd="zabbix_precmd"
required_files="/etc/zabbix_agentd.conf"

# read configuration and set defaultsc
load_rc_config "$name"
: ${zabbix_agentd_enable="NO"}
#: ${zabbix_agentd_pre:=/etc/${name}.pre.sh}

zabbix_agentd_conf="/etc/zabbix_agentd.conf"

if [ ! -z "$zabbix_agentd_conf" ] ; then
  zabbix_agentd_flags="${zabbix_agentd_flags} -c ${zabbix_agentd_conf}"
  required_files=${zabbix_agentd_conf}
fi

zabbix_precmd()
{
  if [ ! -z "$zabbix_agentd_pre" ] ; then
    if [ -e $zabbix_agentd_pre ] ; then
      . $zabbix_agentd_pre
    fi
  fi
}

command="/usr/local/sbin/${name}"

run_rc_command "$1"  run_rc_command "$1"
 Make executable:
  1. chmod +x /etc/rc.d/zabbix_agentd
    
  2. Start daemon:
    /etc/rc.d/zabbix_agentd start
    
  3. Make config files persistent and survive reboots:
    cp /etc/rc.conf /conf/base/etc/
    cp /etc/rc.d/zabbix_agentd /conf/base/etc/rc.d/
    mkdir /conf/etc/zabbix_agentd
    cp /etc/zabbix_agentd.* /conf/base/etc/
    cp /etc/zabbix_agentd.* /conf/base/etc/
     
     

    Zabbix configuration

    Use the template from the zabbix wiki for the host monitoring http://zabbix.org/wiki/File:Template_OS_FreeNAS.xml
     

Monday, July 2, 2018

Install Zabbix agent on FreeNAS 11.x

There is no official Zabbix Agent binary for FreeNAS, so it has to be compiled from source on another machine. There are several options to do so, I decided to just spin up a FreeBSD Vagrant VM to build the binary.
This post is based on the post from [1] with some enhancements 


For more recent howto see here

Vagrant VM

Setup VM & Build Environment

  1. Create Vagrantfile:
    Vagrant.configure("2") do |config|
      config.vm.box = "freebsd/FreeBSD-11.1-STABLE"
      config.vm.base_mac = "000000123456"
    end
    
  2. Start VM: vagrant up
  3. Enter VM: vagrant ssh
  4. Install dependecies:
    sudo pkg install -y curl autoconf automake gettext gcc pcre
    

Compile Zabbix Agent

  1. Download source: https://www.zabbix.com/download_sources#tab:40LTS
  2. curl -fsSL "https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.4.14/zabbix-3.4.14.tar.gz/download" | tar zxvf -
    cd zabbix-3.4.14
    curl -fsSL "https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.0.3/zabbix-4.0.3.tar.gz/download" | tar zxvf -
    cd zabbix-4.0.9
  3. Build with TLS support for encryption:
    ./configure --enable-agent --with-openssl --enable-ipv6
    sudo make install
    
  4. Transfer compiled binary to FreeNAS system:
    scp /usr/local/sbin/zabbix_agentd root@$FREENAS_IP:/usr/local/sbin/
    
  5. Leave VM: exit
  6. Destroy VM (optional): vagrant destroy

FreeNAS

After the zabbix_agentd binary is transferred to the FreeNAS system, it’s time to SSH into it to configure the agent.

Zabbix Agent Configuration

  1. Add user:
    pw groupadd zabbix
    pw useradd zabbix -c "Daemon user for Zabbix agent" -d /nonexistent -s /usr/sbin/nologin -w no -g zabbix 
    Create zabbix user and group via WebUI, otherwise they won't suvive a reboot
  2. Create /etc/zabbix_agentd.conf:
    Server=$ZABBIX_SERVER_IP
    ServerActive=$ZABBIX_SERVER_IP
    Hostname=$ZABBIX_AGENT_HOSTNAME
    LogFile=/tmp/zabbix_agentd.log
    

Daemon Configuration

  1. Enable daemon:
    echo 'zabbix_agentd_enable="YES"' >> /etc/rc.conf
    
  2. Create /etc/rc.d/zabbix_agentd:
    #!/bin/sh
    
    # PROVIDE: zabbix_agentd
    # REQUIRE: DAEMON
    # KEYWORD: shutdown
    #
    # Add the following lines to /etc/rc.conf.local or /etc/rc.conf to
    # enable zabbix_agentd:
    #
    # zabbix_agentd_enable (bool): Set to NO by default.  Set it to YES to
    #         enable zabbix_agentd.
    #
    
    . /etc/rc.subr
    
    name="zabbix_agentd"
    rcvar=zabbix_agentd_enable
    start_precmd="zabbix_precmd"
    required_files="/etc/zabbix_agentd.conf"
    
    # read configuration and set defaultsc
    load_rc_config "$name"
    : ${zabbix_agentd_enable="NO"}
    #: ${zabbix_agentd_pre:=/etc/${name}.pre.sh}
    
    zabbix_agentd_conf="/etc/zabbix_agentd.conf"
    
    if [ ! -z "$zabbix_agentd_conf" ] ; then
      zabbix_agentd_flags="${zabbix_agentd_flags} -c ${zabbix_agentd_conf}"
      required_files=${zabbix_agentd_conf}
    fi
    
    zabbix_precmd()
    {
      if [ ! -z "$zabbix_agentd_pre" ] ; then
        if [ -e $zabbix_agentd_pre ] ; then
          . $zabbix_agentd_pre
        fi
      fi
    }
    
    command="/usr/local/sbin/${name}"
    
    run_rc_command "$1"  run_rc_command "$1"
    
  3. Make executable:
    chmod +x /etc/rc.d/zabbix_agentd
    
  4. Start daemon:
    /etc/rc.d/zabbix_agentd start
    
  5. Make config files persistent and survive reboots:
    cp /etc/rc.conf /conf/base/etc/
    cp /etc/rc.d/zabbix_agentd /conf/base/etc/rc.d/
    cp /etc/zabbix_agentd.* /conf/base/etc/
     

Exit vagrant

in the ssh sesion type: exit
vagrant destroy

 Zabbix configuration

Use the template from the zabbix wiki for the host monitoring
http://zabbix.org/wiki/File:Template_OS_FreeNAS.xml

  1. https://docs.j7k6.org/freenas-zabbix-agent/
  2. https://blag.nullteilerfrei.de/2016/11/26/zabbix-3-0-agent-on-freebsd/
  3. https://www.haphazard.io/blog/install-nagios-nrpe-on-freenas/