Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
New data plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
ripienaar committed May 17, 2012
1 parent 7c4a576 commit 4085831
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 0 deletions.
20 changes: 20 additions & 0 deletions data/augeas_match/data/augeas_match_data.ddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
metadata :name => "Augeas Match",
:description => "Allows agents and discovery to do Augeas match lookups",
:author => "R.I.Pienaar <rip@devco.net>",
:license => "Apache License, Version 2.0",
:version => "1.0",
:url => "http://marionette-collective.org/",
:timeout => 2

dataquery :description => "Match data using Augeas" do
input :query,
:prompt => "Matcher",
:description => "Valid Augeas match expression",
:type => :string,
:validation => /.+/,
:maxlength => 50

output :size,
:description => "The amont of records matched",
:display_as => "Matched"
end
14 changes: 14 additions & 0 deletions data/augeas_match/data/augeas_match_data.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module MCollective
module Data
class Augeas_match_data<Base
require 'augeas'

query do |what|
aug = Augeas.open

result[:size] = aug.match(what).size
end
end
end
end

29 changes: 29 additions & 0 deletions data/resource/data/resource_data.ddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
metadata :name => "Puppet Managed Resources",
:description => "Information about Puppet managed resources",
:author => "R.I.Pienaar <rip@devco.net>",
:license => "ASL 2.0",
:version => "1.0",
:url => "http://marionette-collective.org/",
:timeout => 1

dataquery :description => "Puppet Managed Resources" do
input :query,
:prompt => "Resource Name",
:description => "Valid resource name",
:type => :string,
:validation => /^.+$/,
:optional => true,
:maxlength => 120

output :managed,
:description => "Is the resource managed",
:display_as => "Managed"

output :count,
:description => "Total managed resources",
:display_as => "Count"

output :age,
:description => "Resources list age",
:display_as => "Age"
end
23 changes: 23 additions & 0 deletions data/resource/data/resource_data.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module MCollective
module Data
class Resource_data<Base
activate_when { File.exist?("/var/lib/puppet/state/resources.txt") }

query do |resource|
resources = File.readlines("/var/lib/puppet/state/resources.txt").map {|l| l.chomp}
stat = File.stat("/var/lib/puppet/state/resources.txt")

if resource
result[:managed] = resources.include?(resource.downcase)
else
result[:managed] = false
end

result[:count] = resources.size
result[:age] = Time.now.to_i - stat.mtime.to_i
end
end
end
end


20 changes: 20 additions & 0 deletions data/sysctl/data/sysctl_data.ddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
metadata :name => "Sysctl values",
:description => "Retrieve values for a given sysctl",
:author => "R.I.Pienaar <rip@devco.net>",
:license => "ASL 2.0",
:version => "1.0",
:url => "http://marionette-collective.org/",
:timeout => 1

dataquery :description => "Sysctl values" do
input :query,
:prompt => "Variable Name",
:description => "Valid Variable Name",
:type => :string,
:validation => /^[\w\-\.]+$/,
:maxlength => 120

output :value,
:description => "Kernel Parameter Value",
:display_as => "Value"
end
25 changes: 25 additions & 0 deletions data/sysctl/data/sysctl_data.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module MCollective
module Data
class Sysctl_data<Base
activate_when { File.exist?("/sbin/sysctl") }

query do |sysctl|
shell = Shell.new("/sbin/sysctl %s" % sysctl)
shell.runcommand

if shell.status.exitstatus == 0
value = shell.stdout.chomp.split(/\s*=\s*/)[1]

if value
value = Integer(value) if value =~ /^\d+$/
value = Float(value) if value =~ /^\d+\.\d+$/

result[:value] = value
end
end
end
end
end
end


0 comments on commit 4085831

Please sign in to comment.