Update version according to OSCI-856
[packages/precise/mcollective.git] / plugins / mcollective / agent / rpcutil.rb
1 module MCollective
2   module Agent
3     class Rpcutil<RPC::Agent
4       # Basic system inventory, same as the basic discovery agent
5       action "inventory" do
6         reply[:agents] = Agents.agentlist
7         reply[:facts] = PluginManager["facts_plugin"].get_facts
8         reply[:version] = MCollective.version
9         reply[:classes] = []
10         reply[:main_collective] = config.main_collective
11         reply[:collectives] = config.collectives
12         reply[:data_plugins] = PluginManager.grep(/_data$/)
13
14         cfile = Config.instance.classesfile
15         if File.exist?(cfile)
16           reply[:classes] = File.readlines(cfile).map {|i| i.chomp}
17         end
18       end
19
20       # Retrieve a single fact from the node
21       action "get_fact" do
22         reply[:fact] = request[:fact]
23         reply[:value] = Facts[request[:fact]]
24       end 
25
26       action "get_facts" do
27         response = {}
28         request[:facts].split(',').map { |x| x.strip }.each do |fact|
29           value = Facts[fact]
30           response[fact] = value
31         end
32         reply[:values] = response
33       end
34
35       # Get the global stats for this mcollectied
36       action "daemon_stats" do
37         stats = PluginManager["global_stats"].to_hash
38
39         reply[:threads] = stats[:threads]
40         reply[:agents] = stats[:agents]
41         reply[:pid] = stats[:pid]
42         reply[:times] = stats[:times]
43         reply[:configfile] = Config.instance.configfile
44         reply[:version] = MCollective.version
45
46         reply.data.merge!(stats[:stats])
47       end
48
49       # Builds an inventory of all agents on teh machine
50       # including license, version and timeout information
51       action "agent_inventory" do
52         reply[:agents] = []
53
54         Agents.agentlist.sort.each do |target_agent|
55           agent = PluginManager["#{target_agent}_agent"]
56           actions = agent.methods.grep(/_agent/)
57
58           agent_data = {:agent => target_agent,
59                         :license => "unknown",
60                         :timeout => agent.timeout,
61                         :description => "unknown",
62                         :name => target_agent,
63                         :url => "unknown",
64                         :version => "unknown",
65                         :author => "unknown"}
66
67           agent_data.merge!(agent.meta)
68
69           reply[:agents] << agent_data
70         end
71       end
72
73       # Retrieves a single config property that is in effect
74       action "get_config_item" do
75         reply.fail! "Unknown config property #{request[:item]}" unless config.respond_to?(request[:item])
76
77         reply[:item] = request[:item]
78         reply[:value] = config.send(request[:item])
79       end
80
81       # Responds to PING requests with the local timestamp
82       action "ping" do
83         reply[:pong] = Time.now.to_i
84       end
85
86       # Returns all configured collectives
87       action "collective_info" do
88         config = Config.instance
89         reply[:main_collective] = config.main_collective
90         reply[:collectives] = config.collectives
91       end
92
93       action "get_data" do
94         if request[:query]
95           query = Data.ddl_transform_input(Data.ddl(request[:source]), request[:query].to_s)
96         else
97           query = nil
98         end
99
100         data = Data[ request[:source] ].lookup(query)
101
102         data.keys.each do |key|
103           reply[key] = data[key]
104         end
105       end
106     end
107   end
108 end