voxpupuli / puppet-zabbix

Puppet module for creating and maintaining zabbix components with puppet.
https://forge.puppet.com/puppet/zabbix
Apache License 2.0
80 stars 228 forks source link

How this zabbix::template works? #356

Open mths0x5f opened 7 years ago

mths0x5f commented 7 years ago

How this zabbix::template works? I'm testing this module for installing 3 nodes. But when I try to import a template to Zabbix, it just copies the template to /etc/zabbix/imported_templates on the node; it doesn't import to Zabbix, as I can't see the template on Web interface.

# Desativar SELinux e firewalld em todos os nodes
class { 'selinux':
  mode => 'disabled',
}
service { 'firewalld':
  ensure => 'stopped',
  enable => false,
}

# Inclui repo EPEL
include epel

# Configura o(s) servidor(es) DNS a ser(em) usado(s)
class { 'dnsclient':
  search      => 'puppet',
  nameservers => ['192.168.0.49'],
}

node 'agent1.puppet' {
# Node com Zabbix Server e Web

  class { 'apache':
    mpm_module => 'prefork',
  }
  class { 'apache::mod::php': }

  # Este módulo remove o arquivo /etc/httpd/conf.d/zabbix.conf e cria outro,
  # gerenciado por ele, em seu lugar: /etc/httpd/conf.d/25-agent1.puppet.conf
  class { 'zabbix::web':
    zabbix_version  => '3.0',
    zabbix_url      => 'agent1.puppet', # domínio para acessar via navegador
    zabbix_server   => 'agent1.puppet',
    zabbix_timezone => 'America/Sao_Paulo',
    database_host  => 'agent2.puppet',
    database_type  => 'mysql',
    manage_resources => true,

  }

  class { 'mysql::client': }

  # Módulo que instala o Zabbix Server e
  # gerencia o arquivo /etc/zabbix/zabbix_server.conf
  class { 'zabbix::server':
    zabbix_version  => '3.0',
    database_host   => 'agent2.puppet',
    database_type   => 'mysql',
    # ----------------------------------------------
    manage_firewall  => true,
  }

  class { 'zabbix::agent':
    zabbix_version  => '3.0',
    server          => 'agent1.puppet, agent3.puppet',
  }

zabbix::template { 'teste2':
  templ_source => 'puppet:///modules/zabbix/templates/zabbix.xml',
}

}

node 'agent2.puppet' {
# Node com MySQL

  class { 'mysql::server':
    override_options => {
      'mysqld'       => {
        'bind_address' => '192.168.0.47', # endereço da máquina
      },
    },
  }
  class { 'zabbix::database':
    database_type => 'mysql',
    zabbix_server => 'agent1.puppet',
    zabbix_web    => 'agent1.puppet',
  }
  class { 'zabbix::agent':
    zabbix_version  => '3.0',
    server          => 'agent1.puppet, agent3.puppet',
  }

}

node 'agent3.puppet' {
# Node(s) com Zabbix Proxy

  file { '/var/lib/sqlite':
    ensure => 'directory',
    mode   => '0777',
  }

  # Módulo que instala o Zabbix Proxy e
  # gerencia o arquivo /etc/zabbix/zabbix_proxy.conf
  class { 'zabbix::proxy':
    zabbix_version     => '3.0',
    zabbix_server_host => 'agent1.puppet',
    logfilesize        => '0',
    database_type      => 'sqlite',
    database_name      => '/var/lib/sqlite/zabbix_proxy.db',
    snmptrapper        => '1',
    # ----------------------------------------------
    manage_firewall    => true,
  }

  class { 'zabbix::agent':
    zabbix_version  => '3.0',
    server          => 'agent1.puppet, agent3.puppet',
    serveractive    => 'agent1.puppet, agent3.puppet',
  }

}
alexjfisher commented 7 years ago

I think the zabbix::template defined type is for when end servers declare templates that the zabbix server collects via puppet db. Something like that anyway!!

It looks like you'd probably have more success if you used the zabbix_template native type directly instead.

Fabian1976 commented 6 years ago

As far as I know, loading custom templates doesn't require a puppetdb. Assigning them to hosts does.

I use roles and profiles and in my profile I have this:

class profile::zabbix::full_server (
  String $version = 'present',
  Boolean $configure_firewall_rules = true,
  Boolean $manage_repo = false,
  String $zabbix_url = $::facts['networking']['fqdn'],
  Boolean $apply_api34_patch = false,
  Optional[Hash[String, Struct[{templ_source => String[1]}]]] $templates = undef
){
  class { '::zabbix':
    javagateway     => $::profile::zabbix::javagateway::listenip,
    manage_firewall => $configure_firewall_rules,
    zabbix_url      => $zabbix_url,
    manage_repo     => $manage_repo,
  }
  if $configure_firewall_rules {
    firewall { '200 Zabbix web access':
      chain  => $::input_chain_name,
      proto  => 'tcp',
      action => 'accept',
      dport  => [ 80, 443 ],
    }
  }
  #not all selinux is managed by the Zabbix module
  if $::facts['selinux'] == true {
    selboolean{[ 'httpd_can_network_connect', 'httpd_can_network_connect_db' ]:
      persistent => true,
      value      => 'on',
    }
  }
  if $::zabbix::manage_resources and $apply_api34_patch {
    file_line { 'Apply zabbixapi patch for 3.4':
      path  => '/opt/puppetlabs/puppet/lib/ruby/gems/2.1.0/gems/zabbixapi-3.2.1/lib/zabbixapi/client.rb',
      line  => '      unless api_version =~ /(2\.4|3\.[024])\.\d+/',
      match => '      unless api_version',
    }
  }
  if $templates {
    create_resources('::zabbix::template', $templates)
  }
}

I created a custom module called zabbix_templates_generic in which I only have a files folder with all the templates.

And in my hiera i define them like this:

profile::zabbix::full_server::templates:
  'C_Template App Zabbix Server':
    templ_source: 'puppet:///modules/zabbix_templates_generic/C_Template App Zabbix Server.xml'
  'C_Template OS Linux':
    templ_source: 'puppet:///modules/zabbix_templates_generic/C_Template OS Linux.xml'