Skip to content

Commit

Permalink
Merge 0b6f8a1 into 5d466cf
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandriegorov committed May 29, 2020
2 parents 5d466cf + 0b6f8a1 commit 492f9e5
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
13 changes: 7 additions & 6 deletions manifests/plugin/dbi/database.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#
define collectd::plugin::dbi::database (
String $driver,
String $ensure = 'present',
Optional[String] $host = undef,
String $databasename = $name,
Hash $driveroption = {},
Optional[String] $selectdb = undef,
Array $query = [],
String $ensure = 'present',
Optional[String] $host = undef,
String $databasename = $name,
Hash $driveroption = {},
Optional[String] $selectdb = undef,
Array $query = [],
Optional[Integer[1]] $db_query_interval = undef,
) {

include collectd
Expand Down
49 changes: 49 additions & 0 deletions spec/classes/collectd_plugin_dbi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
it "Will create #{options[:plugin_conf_dir]}/dbi-config.conf" do
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{Driver \"mysql\"\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{Host \"localhost\"\n})
is_expected.not_to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{Interval})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{Query \"disk_io\"\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{DriverOption \"host\" \"db\.example\.com\"\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{DriverOption \"username\" \"dbuser\"\n})
Expand All @@ -67,6 +68,54 @@
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_query_log_delay').with(content: %r{ValuesFrom \"log_delay\"\n})
end
end

context ':ensure => present and create a db with a query and certain interval' do
let(:params) do
{
databases: {
'mydatabase' => {
'host' => 'localhost',
'driver' => 'mysql',
'db_query_interval' => 60,
'driveroption' => {
'host' => 'db.example.com',
'username' => 'dbuser',
'password' => 'dbpasswd'
},
'selectdb' => 'db',
'query' => %w[disk_io log_delay]
}
},
queries: {
'log_delay' => {
'statement' => 'SELECT * FROM log_delay_repli;',
'results' => [{
'type' => 'gauge',
'instanceprefix' => 'log_delay',
'instancesfrom' => %w[inet_server_port inet_server_host],
'valuesfrom' => 'log_delay'
}]
}
}
}
end

it "Will create #{options[:plugin_conf_dir]}/dbi-config.conf with Interval" do
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{Driver \"mysql\"\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{Host \"localhost\"\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{Interval 60\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{Query \"disk_io\"\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{DriverOption \"host\" \"db\.example\.com\"\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{DriverOption \"username\" \"dbuser\"\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_db_mydatabase').with(content: %r{DriverOption \"password\" \"dbpasswd\"\n})

is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_query_log_delay').with(content: %r{Statement \"SELECT \* FROM log_delay_repli;\"\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_query_log_delay').with(content: %r{<Result>\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_query_log_delay').with(content: %r{InstancesFrom \"inet_server_port\" \"inet_server_host\"\n})
is_expected.to contain_concat__fragment('collectd_plugin_dbi_conf_query_log_delay').with(content: %r{ValuesFrom \"log_delay\"\n})
end
end

end
end
end
3 changes: 3 additions & 0 deletions templates/plugin/dbi/database.conf.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<Database "<%= @databasename %>">
Driver "<%= @driver %>"
<% if @db_query_interval -%>
Interval <%= @db_query_interval %>
<% end -%>
<% @driveroption.each do |key, value| -%>
DriverOption "<%= key %>" "<%= value %>"
<% end -%>
Expand Down

0 comments on commit 492f9e5

Please sign in to comment.