Faidon Liambotis has uploaded a new change for review. https://gerrit.wikimedia.org/r/106694
Change subject: Add librenms module and role class & apply it ...................................................................... Add librenms module and role class & apply it LibreNMS is a GPL Observium fork. Sets up Apache, user accounts, cron jobs and provisions via Trebuchet from an internal git mirror. Change-Id: I61073f915b8c5a5b26b28c60b6888563a268c6b1 --- M manifests/role/deployment.pp A manifests/role/librenms.pp M manifests/site.pp A modules/librenms/files/logrotate A modules/librenms/lib/puppet/parser/functions/phpdump.rb A modules/librenms/manifests/init.pp A modules/librenms/templates/config.php.erb 7 files changed, 211 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/operations/puppet refs/changes/94/106694/1 diff --git a/manifests/role/deployment.pp b/manifests/role/deployment.pp index 6d32a44..784048a 100644 --- a/manifests/role/deployment.pp +++ b/manifests/role/deployment.pp @@ -133,6 +133,10 @@ 'grain' => 'scholarships', 'upstream' => 'https://gerrit.wikimedia.org/r/wikimedia/wikimania-scholarships', }, + 'librenms/librenms' => { + 'grain' => 'librenms', + 'upstream' => 'https://gerrit.wikimedia.org/r/operations/software/librenms', + }, } } diff --git a/manifests/role/librenms.pp b/manifests/role/librenms.pp new file mode 100644 index 0000000..f817ee4 --- /dev/null +++ b/manifests/role/librenms.pp @@ -0,0 +1,65 @@ +class role::librenms { + system::role { 'librenms': description => 'LibreNMS server' } + + include network::constants + include passwords::mysql::librenms + include passwords::network + + $hostname = 'librenms.wikimedia.org' + + deployment::target { 'librenms': } + $install_dir = '/srv/deployment/librenms/librenms' + + $config = { + 'install_dir' => $install_dir, + 'html_dir' => "${install_dir}/html", + 'log_file' => '/var/log/librenms.log', + 'rrd_dir' => '/srv/librenms/rrd', + + 'db_host' => 'db1001.eqiad.wmnet', + 'db_user' => $passwords::mysql::librenms::user, + 'db_pass' => $passwords::mysql::librenms::pass, + 'db_name' => 'librenms', + + 'snmp' => { + 'community' => [ $passwords::network::snmp ], + }, + + 'enable_inventory' => 1, + 'enable_syslog' => 1, + 'email_backend' => 'sendmail', + 'alerts' => { + 'port_util_alert' => true, + 'port_util_perc' => 85, + 'email' => { + 'default' => 'n...@wikimedia.org', + 'enable' => true, + }, + 'port' => { + 'ifdown' => false, + }, + }, + + 'auth_mechanism' => 'mysql', + 'nets' => $network::constants::external_networks, + } + + class { 'librenms': + install_dir => $install_dir, + config => $config, + } + + @webserver::apache::module { 'php5': } + @webserver::apache::site { 'librenms.wikimedia.org': + docroot => $install_dir, + require => [ + Webserver::Apache::Module['php5'], + Class['librenms'], + ], + } + + monitor_service { 'librenms': + description => 'HTTP', + check_command => "check_http_url!${hostname}!http://${hostname}", + } +} diff --git a/manifests/site.pp b/manifests/site.pp index 66b3b26..0298010 100644 --- a/manifests/site.pp +++ b/manifests/site.pp @@ -1891,7 +1891,8 @@ webserver::apache, misc::rancid, smokeping, - smokeping::web + smokeping::web, + role::librenms } node /^nfs[12].pmtpa.wmnet/ { diff --git a/modules/librenms/files/logrotate b/modules/librenms/files/logrotate new file mode 100644 index 0000000..8766aa7 --- /dev/null +++ b/modules/librenms/files/logrotate @@ -0,0 +1,6 @@ +/var/log/librenms.log { + rotate 7 + daily + compress + missingok +} diff --git a/modules/librenms/lib/puppet/parser/functions/phpdump.rb b/modules/librenms/lib/puppet/parser/functions/phpdump.rb new file mode 100644 index 0000000..2033613 --- /dev/null +++ b/modules/librenms/lib/puppet/parser/functions/phpdump.rb @@ -0,0 +1,34 @@ +# == Function: phpdump +# +# Serialize a hash into PHP array with lexicographically sorted keys. +# + +def phpdump(o, level=1) + indent = " "*4 + + case o + when Hash + contents = '' + o.sort.each do |k, v| + contents += indent*level + contents += "\"#{k}\" => " + phpdump(v, level+1) + contents += ",\n" + end + "array(\n" + contents + indent*(level-1) + ")" + when Array + "array(" + o.map { |x| phpdump(x, level+1) }.join(', ') + ")" + when TrueClass + "TRUE" + when FalseClass + "FALSE" + else + '"' + o.to_s + '"' + end +end + +module Puppet::Parser::Functions + newfunction(:phpdump, :type => :rvalue) do |args| + fail 'phpdump() requires an argument' if args.empty? + phpdump(args.inject(:merge)) + end +end diff --git a/modules/librenms/manifests/init.pp b/modules/librenms/manifests/init.pp new file mode 100644 index 0000000..3197042 --- /dev/null +++ b/modules/librenms/manifests/init.pp @@ -0,0 +1,94 @@ +# == Class: librenms +# +# This class installs & manages LibreNMS, a fork of Observium +# +# == Parameters +# +# [*config*] +# Configuration for LibreNMS, in a puppet hash format. +# +# [*install_dir*] +# Installation directory for LibreNMS. +# +class librenms( + $config, + $install_dir, +) { + group { 'librenms': + ensure => present, + } + + user { 'librenms': + ensure => present, + gid => 'librenms', + shell => '/bin/false', + home => '/nonexistent', + system => true, + managehome => false, + } + + file { $install_dir: + ensure => directory, + owner => 'www-data', + group => 'librenms', + mode => '0550', + require => Group['librenms'], + } + + file { "${install_dir}/config.php": + ensure => present, + owner => 'www-data', + group => 'librenms', + mode => '0440', + content => template('librenms/config.php.erb'), + require => Group['librenms'], + } + + file { '/etc/logrotate.d/librenms': + ensure => present, + owner => 'root', + group => 'root', + source => 'puppet:///modules/librenms/logrotate', + } + + package { [ + 'php5-cli', + 'php5-gd', + 'php5-json', + 'php5-mcrypt', + 'php5-mysql', + 'php5-snmp', + 'php-pear', + 'fping', + 'graphviz', + 'imagemagick', + 'ipmitool', + 'mtr-tiny', + 'nmap', + 'python-mysqldb', + 'rrdtool', + 'whois', + ]: + ensure => present, + } + + cron { 'librenms-discovery-all': + ensure => present, + user => 'librenms', + command => "${install_dir}/discovery.php -h all >> /dev/null 2>&1", + hour => '*/6', + minute => '33', + } + cron { 'librenms-discovery-new': + ensure => present, + user => 'librenms', + command => "${install_dir}/discovery.php -h all >> /dev/null 2>&1", + minute => '*/5', + } + cron { 'librenms-poller-all': + ensure => present, + user => 'librenms', + command => "${install_dir}/poller.php -h all >> /dev/null 2>&1", + minute => '*/5', + } +} diff --git a/modules/librenms/templates/config.php.erb b/modules/librenms/templates/config.php.erb new file mode 100644 index 0000000..b65bc2f --- /dev/null +++ b/modules/librenms/templates/config.php.erb @@ -0,0 +1,6 @@ +<?php +# This file is managed by Puppet! + +$config = <%= scope.function_phpdump(@config) %>; + +?> -- To view, visit https://gerrit.wikimedia.org/r/106694 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I61073f915b8c5a5b26b28c60b6888563a268c6b1 Gerrit-PatchSet: 1 Gerrit-Project: operations/puppet Gerrit-Branch: production Gerrit-Owner: Faidon Liambotis <fai...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits