Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Commit

Permalink
Add influxdbwriter object deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Skopenko committed Sep 28, 2017
1 parent 5bb4bf0 commit f0ba72c
Show file tree
Hide file tree
Showing 4 changed files with 311 additions and 0 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ Currently icinga2 cookbook supports below Objects LWRP Resources:
- icinga2_feature
- icinga2_gelfwriter
- icinga2_graphitewriter
- icinga2_influxdbwriter
- icinga2_host
- icinga2_hostgroup
- icinga2_idomysqlconnection
Expand Down Expand Up @@ -1453,6 +1454,46 @@ Above LWRP resource will create an icinga `GraphiteWriter` config object.
- *service_name_template* (optional, String) - default icinga.$host.name$.$service.name$, icinga `GraphiteWriter` attribute `service_name_template`


## LWRP icinga2_influxdbwriter

LWRP `influxdbwriter` creates an icinga `InfluxdbWriter` object.


**LWRP InfluxdbWriter example**

icinga2_influxdbwriter 'influxdbwriter' do
library 'library'
host 'host address'
port 8087
database 'icinga2'
username 'myuser'
password 'mypassword'
end

Above LWRP resource will create an icinga `InfluxdbWriter` config object.


**LWRP Options**

- *action* (optional) - default :enable, options: :enable, :disable
- *library* (optional, String) - default 'perfdata', icinga `InfluxdbWriter` attribute `library`
- *host* (optional, String) - default 'localhost', icinga `InfluxdbWriter` attribute `host`
- *port* (optional, Integer) - default 8087, icinga `InfluxdbWriter` attribute `port`
- *database* (optional, String) - default 'icinga2', icinga `InfluxdbWriter` attribute `database`
- *username* (optional, String) - icinga `InfluxdbWriter` attribute `username`
- *password* (optional, String) - icinga `InfluxdbWriter` attribute `password`
- *ssl_enable* (optional, String) - default 'false', icinga `InfluxdbWriter` attribute `ssl_enable`
- *ssl_ca_cert* (optional, String) - icinga `InfluxdbWriter` attribute `ssl_ca_cert`
- *ssl_cert* (optional, String) - icinga `InfluxdbWriter` attribute `ssl_cert`
- *ssl_key* (optional, String) - icinga `InfluxdbWriter` attribute `ssl_key`
- *host_template* (optional, String) - icinga `InfluxdbWriter` attribute `host_template`
- *service_template* (optional, String) - icinga `InfluxdbWriter` attribute `service_template`
- *enable_send_thresholds* (optional, String) - icinga `InfluxdbWriter` attribute `enable_send_thresholds`
- *enable_send_metadata* (optional, String) - icinga `InfluxdbWriter` attribute `enable_send_metadata`
- *flush_intervald* (optional, String) - icinga `InfluxdbWriter` attribute `flush_intervald`
- *flush_threshold* (optional, Integer) - icinga `InfluxdbWriter` attribute `flush_threshold`


## LWRP icinga2_idomysqlconnection

LWRP `idomysqlconnection` creates an icinga `IdoMySqlConnection` object.
Expand Down
202 changes: 202 additions & 0 deletions libraries/resource_influxdbwriter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
# frozen_string_literal: true
# resource
class Chef
class Resource
# provides icinga2_influxdbwriter
class Icinga2Influxdbwriter < Chef::Resource
identity_attr :name

def initialize(name, run_context = nil)
super
@resource_name = :icinga2_influxdbwriter if respond_to?(:resource_name)
@provides = :icinga2_influxdbwriter
@provider = Chef::Provider::Icinga2Influxdbwriter
@action = :create
@allowed_actions = [:create, :delete, :nothing]
@name = name
end

def library(arg = nil)
set_or_return(
:library, arg,
:kind_of => String,
:default => 'perfdata'
)
end

def host(arg = nil)
set_or_return(
:host, arg,
:kind_of => String,
:default => 'localhost'
)
end

def port(arg = nil)
set_or_return(
:port, arg,
:kind_of => Integer,
:default => 8087
)
end

def database(arg = nil)
set_or_return(
:database, arg,
:kind_of => String,
:default => 'icinga2'
)
end

def username(arg = nil)
set_or_return(
:username, arg,
:kind_of => String,
:default => nil
)
end

def password(arg = nil)
set_or_return(
:password, arg,
:kind_of => String,
:default => nil
)
end

def ssl_enable(arg = nil)
set_or_return(
:ssl_enable, arg,
:kind_of => String,
:default => false
)
end

def ssl_ca_cert(arg = nil)
set_or_return(
:ssl_ca_cert, arg,
:kind_of => String,
:default => nil
)
end

def ssl_cert(arg = nil)
set_or_return(
:ssl_cert, arg,
:kind_of => String,
:default => nil
)
end

def ssl_key(arg = nil)
set_or_return(
:ssl_key, arg,
:kind_of => String,
:default => nil
)
end

def host_template(arg = nil)
set_or_return(
:host_template, arg,
:kind_of => String,
:default => nil
)
end

def service_template(arg = nil)
set_or_return(
:service_template, arg,
:kind_of => String,
:default => nil
)
end

def enable_send_thresholds(arg = nil)
set_or_return(
:enable_send_thresholds, arg,
:kind_of => String,
:default => nil
)
end

def enable_send_metadata(arg = nil)
set_or_return(
:enable_send_metadata, arg,
:kind_of => String,
:default => nil
)
end

def flush_interval(arg = nil)
set_or_return(
:flush_interval, arg,
:kind_of => String,
:default => nil
)
end

def flush_threshold(arg = nil)
set_or_return(
:flush_threshold, arg,
:kind_of => String,
:default => nil
)
end
end
end
end

# provider
class Chef
class Provider
# provides icinga2_influxdbwriter
class Icinga2Influxdbwriter < Chef::Provider::LWRPBase
provides :icinga2_influxdbwriter if respond_to?(:provides)

def whyrun_supported?
true
end

action :create do
new_resource.updated_by_last_action(object_template)
end

action :delete do
new_resource.updated_by_last_action(object_template)
end

protected

def object_template
resource_name = new_resource.resource_name.to_s.gsub('icinga2_', '')
ot = template ::File.join(node['icinga2']['objects_dir'], "#{resource_name}.conf") do
source "object.#{resource_name}.conf.erb"
cookbook 'icinga2'
owner node['icinga2']['user']
group node['icinga2']['group']
mode 0o640
variables(:object => new_resource.name,
:library => new_resource.library,
:host => new_resource.host,
:port => new_resource.port,
:database => new_resource.database,
:username => new_resource.username,
:password => new_resource.password,
:ssl_enable => new_resource.ssl_enable,
:ssl_ca_cert => new_resource.ssl_ca_cert,
:ssl_cert => new_resource.ssl_cert,
:ssl_key => new_resource.ssl_key,
:host_template => new_resource.host_template,
:service_template => new_resource.service_template,
:enable_send_thresholds => new_resource.enable_send_thresholds,
:enable_send_metadata => new_resource.enable_send_metadata,
:flush_interval => new_resource.flush_interval,
:flush_threshold => new_resource.flush_threshold)
notifies platform?('windows') ? :restart : :reload, 'service[icinga2]'
end
ot.updated?
end
end
end
end
10 changes: 10 additions & 0 deletions spec/support/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ def delete_icinga2_graphitewriter(name)
.new(:icinga2_graphitewriter, :delete, name)
end

def create_icinga2_influxdbwriter(name)
ChefSpec::Matchers::ResourceMatcher
.new(:icinga2_influxdbwriter, :create, name)
end

def delete_icinga2_influxdbwriter(name)
ChefSpec::Matchers::ResourceMatcher
.new(:icinga2_influxdbwriter, :delete, name)
end

def create_icinga2_host(name)
ChefSpec::Matchers::ResourceMatcher
.new(:icinga2_host, :create, name)
Expand Down
58 changes: 58 additions & 0 deletions templates/default/object.influxdbwriter.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* This file is managed by Chef.
* Do NOT modify this file directly.
*/

/**
* InfluxdbWriter Object.
*/

library <%= @library.inspect %>

object InfluxdbWriter <%= @object.inspect -%> {
<% if @host -%>
host = <%= @host.inspect %>
<% end -%>
<% if @port -%>
port = <%= @port.inspect %>
<% end -%>
<% if @database -%>
database = <%= @database.inspect %>
<% end -%>
<% if @username -%>
username = <%= @username.inspect %>
<% end -%>
<% if @password -%>
password = <%= @password.inspect %>
<% end -%>
<% if @ssl_enable -%>
ssl_enable = <%= @ssl_enable %>
<% end -%>
<% if @ssl_ca_cert -%>
ssl_ca_cert = <%= @ssl_ca_cert.inspect %>
<% end -%>
<% if @ssl_cert -%>
ssl_cert = <%= @ssl_cert.inspect %>
<% end -%>
<% if @ssl_key -%>
ssl_key = <%= @ssl_key.inspect %>
<% end -%>
<% if @host_template -%>
host_template = <%= @host_template %>
<% end -%>
<% if @service_template -%>
service_template = <%= @service_template %>
<% end -%>
<% if @enable_send_thresholds -%>
enable_send_thresholds = <%= @enable_send_thresholds.inspect %>
<% end -%>
<% if @enable_send_metadata -%>
enable_send_metadata = <%= @enable_send_metadata.inspect %>
<% end -%>
<% if @flush_interval -%>
flush_interval = <%= @flush_interval %>
<% end -%>
<% if @flush_threshold -%>
flush_threshold = <%= @flush_threshold %>
<% end -%>
}

0 comments on commit f0ba72c

Please sign in to comment.