forked from Normation/rudder-techniques
/
fusionAgent.cf
585 lines (465 loc) · 21.7 KB
/
fusionAgent.cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
#####################################################################################
# Copyright 2011 Normation SAS
#####################################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#####################################################################################
#
# This file launch a fusion-inventory agent
# inventory in local.
# If fusion agent is not installed,
# the installation is done
#
# Then the inventory file is improved with external informations (UUID, cf-key, VMs)
bundle agent doInventory {
commands:
(linux|android)::
"$(g.rudder_curl)"
args => "-s -f -o \"$(g.rudder_var_tmp)/uuid.txt\" http://${server_info.cfserved}/uuid",
comment => "Getting the uuid from the server",
classes => if_else("uuid_succesfully_downloaded","could_not_download_uuid");
windows::
"\"${g.rudder_base_sbin}\curl\curl.exe\""
args => "-s -f -o \"$(g.rudder_var_tmp)\uuid.txt\" http://${server_info.cfserved}/uuid",
comment => "Getting the uuid from the server",
classes => if_else("uuid_succesfully_downloaded","could_not_download_uuid");
vars:
(linux|android).uuid_succesfully_downloaded::
"policy_server_uuid" string => readfile("$(g.rudder_var_tmp)/uuid.txt", 50);
windows.uuid_succesfully_downloaded::
"policy_server_uuid" string => readfile("$(g.rudder_var_tmp)/uuid.txt", 50);
classes:
uuid_succesfully_downloaded::
"uuid_valid" expression => regcmp("[a-z0-9-]+","$(policy_server_uuid)");
"uuid_validity_checked"
expression => "any",
comment => "This dummy class is just used for ordering the report using !uuid_valid below";
methods:
uuid_valid.(!inventory_sent|force_inventory)::
"any" usebundle => fusionAgent;
"any" usebundle => listInstalledVM;
"any" usebundle => generateExtraInformations;
"any" usebundle => turnUsersToUnicode;
"any" usebundle => addInformationsToInventory;
"any" usebundle => moveInventoryToFinalDestination;
"any" usebundle => sendInventory;
reports:
could_not_download_uuid::
"@@Inventory@@result_error@@inventory-all@@inventory-all@@00@@inventory@@None@@$(g.execRun)##$(g.uuid)@#Could not retrieve the UUID of the policy server";
uuid_succesfully_downloaded.uuid_validity_checked.!uuid_valid::
"@@Inventory@@result_error@@inventory-all@@inventory-all@@00@@inventory@@None@@$(g.execRun)##$(g.uuid)@#Could not retrieve a valid UUID from the policy server";
# Send reports to confirm this PT's success even if we don't need to send an inventory
inventory_sent::
"@@Inventory@@log_info@@inventory-all@@inventory-all@@00@@inventory@@None@@$(g.execRun)##$(g.uuid)@#An inventory was already sent less than 8 hours ago";
!(Night.splaying).!force_inventory::
"@@Inventory@@result_success@@inventory-all@@inventory-all@@00@@inventory@@None@@$(g.execRun)##$(g.uuid)@#Next inventory scheduled between 00:00 and 06:00";
}
bundle common inventory {
vars:
windows::
# Files names
"UserListFile_cp" string => "${g.rudder_var_tmp}\UserList.tmp";
"UserListFile" string => "${g.rudder_var_tmp}\UserList.list";
any::
"CPUIDFile" string => "${g.rudder_var_tmp}/cpuid.arc";
}
bundle agent fusionAgent {
files:
android|linux|cygwin::
"${g.rudder_var_tmp}/inventory/."
create => "true",
comment => "Creating inventory directory",
classes => if_ok("inventoryfoldercreated");
"${g.rudder_var_reports}/."
create => "true";
windows.!cygwin::
"${g.rudder_var_tmp}\inventory\."
create => "true",
comment => "Creating inventory directory",
classes => if_ok("inventoryfoldercreated");
"${g.rudder_var_reports}\."
create => "true";
packages:
xen.(redhat|centos|SuSE)::
"xen"
package_policy => "add",
package_method => generic,
classes => cf2_if_else("xen_installed", "cant_install_xen"),
comment => "Installing xen package for extended data";
xen.debian::
"xenstore-utils"
package_policy => "add",
package_method => generic,
classes => cf2_if_else("xen_installed", "cant_install_xen"),
comment => "Installing xen package for extended data";
commands:
(android|linux).inventoryfoldercreated::
"${g.rudder_base}/bin/run-inventory --local=${g.rudder_var_tmp}/inventory --scan-homedirs",
classes => cf2_if_else("run_inventory", "inventory_failed"),
comment => "Generating inventory, in the temporary folder";
windows::
"\"${g.rudder_base_sbin}\perl\bin\perl.exe\""
args => "\"${g.rudder_base_sbin}\perl\bin\fusioninventory-agent\" --local=\"${g.rudder_var_tmp}\inventory\" --scan-homedirs 2>nul",
contain => in_shell,
classes => cf2_if_else("run_inventory", "inventory_failed"),
comment => "Generating inventory";
reports:
run_inventory::
"@@Inventory@@log_debug@@inventory-all@@inventory-all@@00@@inventory@@None@@$(g.execRun)##$(g.uuid)@#Running inventory";
inventory_failed::
"@@Inventory@@result_error@@inventory-all@@inventory-all@@00@@inventory@@None@@$(g.execRun)##$(g.uuid)@#Could not execute the inventory";
cant_install_curl::
"@@Inventory@@result_error@@inventory-all@@inventory-all@@00@@inventory@@None@@$(g.execRun)##$(g.uuid)@#Could not install curl";
cant_install_ocs::
"@@Inventory@@result_error@@inventory-all@@inventory-all@@00@@inventory@@None@@$(g.execRun)##$(g.uuid)@#Could not install ocs";
curl_installed::
"@@Inventory@@log_info@@inventory-all@@inventory-all@@00@@inventory@@None@@$(g.execRun)##$(g.uuid)@#Curl installed";
cant_install_xen::
"@@Inventory@@result_error@@&TRACKINGKEY&@@inventory@@None@@$(g.execRun)##$(g.uuid)@#Could not install xen utils on xen systems";
xen_installed::
"@@Inventory@@log_info@@&TRACKINGKEY&@@inventory@@None@@$(g.execRun)##$(g.uuid)@#Xen utils installed";
}
# List all installed VM on the machine (based on VirtualBox)
# CAUTION : Issue with path containing a whitespace, it's not working with windows
bundle agent listInstalledVM {
commands:
linux.VirtualBoxInstalled::
"/usr/bin/VBoxManage"
args => "-q list vms > ${virtualMachines.VBoxListFile}",
contain => outputable,
classes => cf2_if_else("vb_listed", "cant_list_vb"),
comment => "Generating file with list of VM";
windows.VirtualBoxInstalled::
"\"${virtualMachines.virtual_box_install_path}VBoxManage.exe\""
args => "-q list vms > ${virtualMachines.VBoxListFile}",
contain => outputable,
classes => cf2_if_else("vb_listed", "cant_list_vb"),
comment => "Generating file with list of VM";
linux.VMWareInstalled::
"${virtualMachines.VMWareScript}"
contain => outputable,
args => " > ${virtualMachines.VMWareListFile}",
classes => cf2_if_else("vm_listed", "cant_list_vm"),
comment => "Generating file with list of VM";
windows.VMWareInstalled::
"${virtualMachines.VMWareScript}"
contain => outputable,
args => " > ${virtualMachines.VMWareListFile}",
classes => cf2_if_else("vm_listed", "cant_list_vm"),
comment => "Generating file with list of VM";
files:
VirtualBoxInstalled::
"${virtualMachines.VBoxListFile}"
create => "true",
edit_line => xmlify($(virtualMachines.VBoxAttr)),
comment => "Converting file into pseudo XML";
VMWareInstalled::
"${virtualMachines.VMWareListFile}"
create => "true",
edit_line => xmlify($(virtualMachines.VMWareAttr)),
comment => "Converting file into pseudo XML";
reports:
cant_list_vm::
"@@Inventory@@log_warn@@inventory-all@@inventory-all@@00@@inventory@@None@@$(g.execRun)##$(g.uuid)@#Could not list installed VMWare machines";
cant_list_vb::
"@@Inventory@@log_warn@@inventory-all@@inventory-all@@00@@inventory@@None@@$(g.execRun)##$(g.uuid)@#Could not list installed VirtualBox machines";
}
bundle agent generateExtraInformations {
commands:
windows::
"\"${g.rudder_dependencies}\userlist.bat\""
args => " > \"${inventory.UserListFile_cp}\" ",
contain => outputable,
classes => cf2_if_else("userlist", "userlist_fail"),
comment => "Generating file with list of users";
"${sys.winsysdir}\cscript.exe"
args => "/Nologo \"${g.rudder_dependencies}/cpuid-windows-V1.0.vbs\" > \"${inventory.CPUIDFile}\"",
contain => outputable,
classes => cf2_if_else("cpuid", "cpuid_fail"),
comment => "Generating file with CPUID information";
linux.!android::
"${g.rudder_dependencies}/cpuid-linux-V1.0.sh"
args => " > ${inventory.CPUIDFile}",
contain => outputable,
classes => cf2_if_else("cpuid", "cpuid_fail"),
comment => "Generating file with CPUID information";
android::
"${g.rudder_dependencies}/cpuid-android-V1.0.sh"
args => " > ${inventory.CPUIDFile}",
contain => outputable,
classes => cf2_if_else("cpuid", "cpuid_fail"),
comment => "Generating file with CPUID information";
reports:
userlist::
"@@Inventory@@log_debug@@inventory-all@@inventory-all@@00@@inventory@@None@@$(g.execRun)##$(g.uuid)@#Generated the userlist";
cpuid::
"@@Inventory@@log_debug@@inventory-all@@inventory-all@@00@@inventory@@None@@$(g.execRun)##$(g.uuid)@#Generated the CPUID";
userlist_fail::
"@@Inventory@@result_error@@inventory-all@@inventory-all@@00@@inventory@@None@@$(g.execRun)##$(g.uuid)@#Could not generate the user list";
cpuid_fail::
"@@Inventory@@result_error@@inventory-all@@inventory-all@@00@@inventory@@None@@$(g.execRun)##$(g.uuid)@#Could not generate the cpuid";
}
bundle agent turnUsersToUnicode {
commands:
windows::
"\"${g.rudder_dependencies}\iconv.exe\""
args => " -f CP850 -t UTF-8 \"${inventory.UserListFile_cp}\" > \"${inventory.UserListFile}\" ",
contain => outputable_dir("${g.rudder_dependencies}"),
classes => cf2_if_else("userlist", "userlist_fail"),
comment => "Generating file with list of users in UTF";
reports:
windows::
"@@Inventory@@log_debug@@inventory-all@@inventory-all@@00@@inventory@@None@@$(g.execRun)##$(g.uuid)@#This is a windows machine. User list has been converted to Unicode";
}
# adding data to the inventory :
# UUID and CFKey in <DEVICEID>,
# list of VM in <CONTENT>
bundle agent addInformationsToInventory {
vars:
windows.!cygwin::
"CFKEY" string => execresult("${sys.winsysdir}\cmd.exe /c \"type \"${sys.workdir}\ppkeys\localhost.pub\"\"", "noshell");
"USER" string => getenv("USERNAME", 40);
"RUDDERUUID" string => execresult("${sys.winsysdir}\cscript.exe /Nologo \"${g.rudder_dependencies}/uuid.vbs\"","noshell");
"polserv_uuid" string => readfile( "$(g.rudder_var_tmp)\uuid.txt" , "33" );
"users" slist => { readstringlist("${inventory.UserListFile}","#.*","[\n| |\r]",50,4000) };
cygwin::
"mywinpath" string => execresult("/usr/bin/echo $WINDIR ", "useshell");
"CFKEY" string => execresult("/usr/bin/cat ${sys.workdir}/ppkeys/localhost.pub", "noshell");
"USER" string => execresult("/usr/bin/whoami", "noshell");
"RUDDERUUID" string => execresult("${sys.winsysdir}\cscript.exe /Nologo ${g.rudder_dependencies}/uuid.vbs","noshell");
"polserv_uuid" string => readfile( "$(g.rudder_var_tmp)/uuid.txt" , "33" );
"users" slist => { readstringlist("${inventory.UserListFile}","#.*","[\n| |\r]",10,4000) };
xen.SuSE::
"VMRUDDERUUID" string => execresult("/bin/xenstore-read vm","noshell");
xen.!SuSE::
"VMRUDDERUUID" string => execresult("/usr/sbin/xenstore-read vm","noshell");
xen.xenrudderuuid::
"RUDDERUUID" string => "$(vmarray[1])";
(linux|android)::
"CFKEY" string => readfile("${sys.workdir}/ppkeys/localhost.pub", "1024");
"polserv_uuid" string => readfile( "$(g.rudder_var_tmp)/uuid.txt" , "33" );
linux.!android.!xen::
"RUDDERUUID" string => execresult("/usr/sbin/dmidecode -s system-uuid","noshell");
"USER" string => execresult("/usr/bin/whoami", "noshell");
"usersnumber" int => readstringarray("userslist","/etc/passwd","#[^\n]*",":",50,4000);
"users" slist => getindices("userslist");
android::
"RUDDERUUID" string => "<!-- This is an Android machine, the machine ID is autogenerated by Rudder -->";
"USER" string => execresult("/system/xbin/whoami", "noshell");
"usersnumber" int => "1";
"users" slist => {"root"};
"android_kernelname" string => "linux";
"android_kernelversion" string => execresult("/system/xbin/uname -r", "noshell");
"android_name" string => "Android";
"android_version" string => execresult("/system/bin/getprop ro.build.version.release", "noshell");
"android_fullname" string => "Android $(android_version)";
"logdate" string => execresult("/system/bin/date '+%Y-%m-%d %H:%M:%S'", "noshell");
classes:
xen::
"xenrudderuuid" expression => regextract("/vm/(.*)", "$(VMRUDDERUUID)", "vmarray");
any::
"uuiddefined" expression => isvariable("RUDDERUUID");
files:
windows::
"C:/Program Files/Rudder/var/tmp/inventory/.*.ocs"
#"${g.esc_rudder_var_tmp}\inventory\.*.ocs"
edit_line => add_information_to_inventory($(RUDDERUUID), $(CFKEY), $(USER), $(polserv_uuid)),
edit_defaults => def_no_backup,
pathtype => "regex";
"C:/Program Files/Rudder/var/tmp/inventory/.*.ocs"
#"${g.esc_rudder_var_tmp}\inventory\.*.ocs"
edit_line => add_users_information_to_inventory($(users)),
edit_defaults => def_no_backup,
pathtype => "regex";
(linux|android).uuiddefined::
"${g.rudder_var_tmp}/inventory/.*.ocs"
edit_line => add_information_to_inventory($(RUDDERUUID), $(CFKEY), $(USER), $(polserv_uuid)),
edit_defaults => def_no_backup;
"${g.rudder_var_tmp}/inventory/.*.ocs"
edit_line => add_users_information_to_inventory($(users)),
edit_defaults => def_no_backup;
android::
"${g.rudder_var_tmp}/inventory/.*.ocs"
edit_line => add_information_to_android_inventory($(android_fullname), $(android_kernelname), $(android_kernelversion), $(android_name), $(android_version)),
edit_defaults => def_no_backup;
"${g.rudder_var_tmp}/inventory/.*.ocs"
edit_line => add_accesslog_to_android_inventory($(logdate)),
edit_defaults => def_no_backup;
}
# Move the inventory file in the shared directory
bundle agent moveInventoryToFinalDestination {
files:
"${g.rudder_inventories}"
copy_from => copy("$(g.rudder_var_tmp)/inventory"),
depth_search => recurse_visible(1),
file_select => inventory_files,
comment => "Moving inventory files to the final location",
action => bg(30, 10);
}
# Send the file to the promises server
bundle agent sendInventory {
files:
(linux|android)::
"${g.rudder_inventories}"
transformer => "$(g.rudder_curl) -f -s --user $(g.davuser):$(g.davpw) -T $(this.promiser) http://${server_info.cfserved}/inventories/",
depth_search => recurse_visible(1),
file_select => inventory_files,
classes => persistant_class("inventory_sent", "cant_send_inventory", 480),
comment => "Sending the inventory to the server";
# Once we've successfully sent all inventories, remove them
(linux|android).inventory_sent.!cant_send_inventory::
"${g.rudder_inventories}"
transformer => "${g.rudder_rm} -f $(this.promiser)",
depth_search => recurse_visible(1),
file_select => inventory_files,
classes => if_else("inventory_file_deleted", "cant_delete_inventory_file"),
comment => "Cleaning up inventory files already sent to the server";
"${g.rudder_var_tmp}/inventory"
transformer => "${g.rudder_rm} -f $(this.promiser)",
depth_search => recurse_visible(1),
file_select => inventory_files,
classes => if_else("inventory_file_deleted", "cant_delete_inventory_file"),
comment => "Cleaning up inventory files already sent to the server";
# TODO: we should find some way to have an equivalent behaviour to send-clean.sh above on Windows
windows::
"${g.rudder_inventories}"
transformer => "\"${g.rudder_base_sbin}\curl\curl.exe\" -f -s --user $(g.davuser):$(g.davpw) -T \"$(this.promiser)\" http://${server_info.cfserved}/inventories/",
depth_search => recurse_visible(1),
file_select => inventory_files,
classes => persistant_class("inventory_sent", "cant_send_inventory", 480),
comment => "Sending the inventory to the server";
reports:
inventory_sent::
"@@Inventory@@result_success@@inventory-all@@inventory-all@@00@@inventory@@None@@$(g.execRun)##$(g.uuid)@#The inventory has been successfully sent";
cant_send_inventory::
"@@Inventory@@result_error@@inventory-all@@inventory-all@@00@@inventory@@None@@$(g.execRun)##$(g.uuid)@#Could not send the inventory";
cant_delete_inventory_file::
"@@Inventory@@log_warn@@inventory-all@@inventory-all@@00@@inventory@@None@@$(g.execRun)##$(g.uuid)@#Could not delete inventory file after sending to server";
}
#####################################################
#Adding the list of Virtual Machines into the report
#Adding the ids in the report
#####################################################
bundle edit_line add_information_to_inventory(RUDDERUUID, CFKEY, USER, POLSRVUUID)
{
insert_lines:
"<UUID>${g.uuid}</UUID>$(const.n)<USER>$(USER)</USER>$(const.n)<AGENTSNAME>$(const.n)</AGENTSNAME>$(const.n)<MACHINEID>$(RUDDERUUID)</MACHINEID>$(const.n)<CFKEY>$(CFKEY)</CFKEY>$(const.n)<HOSTNAME>$(sys.fqhost)</HOSTNAME>$(const.n)<POLICY_SERVER>$(POLSRVUUID)</POLICY_SERVER>$(const.n)"
location => after_deviceid,
comment => "Add the UUID and CFKEY tags in the inventory file";
any::
"<VMS>$(const.n)</VMS>$(const.n)<USERSLIST>$(const.n)</USERSLIST>" location => after_content;
"${inventory.CPUIDFile}"
insert_type => "file",
location => after_location("<HOSTNAME>"),
comment => "Adding the CPUID data in the inventory file";
nova_edition::
"<AGENTNAME>Nova</AGENTNAME>"
location => after_location("<AGENTSNAME>"),
comment => "Adding the agent data in the inventory file";
community_edition::
"<AGENTNAME>Community</AGENTNAME>"
location => after_location("<AGENTSNAME>"),
comment => "Adding the agent data in the inventory file";
VirtualBoxInstalled::
"${virtualMachines.VBoxListFile}"
insert_type => "file",
location => after_location("<VMS>"),
comment => "Adding the list of VM in the inventory file";
VMWareInstalled::
"${virtualMachines.VMWareListFile}"
insert_type => "file",
location => after_vm,
comment => "Adding the list of VM in the inventory file";
}
bundle edit_line add_information_to_android_inventory(fullname, kernelname, kernelversion, name, version)
{
insert_lines:
android::
"<OPERATINGSYSTEM>$(const.n)<FULL_NAME>$(fullname)</FULL_NAME>$(const.n)<KERNEL_NAME>$(kernelname)</KERNEL_NAME>$(const.n)<KERNEL_VERSION>$(kernelversion)</KERNEL_VERSION>$(const.n)<NAME>$(name)</NAME>$(const.n)<VERSION>$(version)</VERSION>$(const.n)</OPERATINGSYSTEM>"
location => after_location("<CONTENT>"),
comment => "Adding the list of OPERATINGSYSTEM part";
}
#this bundle is necessary for OCSInventory (but not for fusioninventory)
bundle edit_line add_accesslog_to_android_inventory(logdate)
{
insert_lines:
android::
"<ACCESSLOG><LOGDATE>$(logdate)</LOGDATE></ACCESSLOG>"
location => after_location("<CONTENT>"),
comment => "Adding log date";
}
bundle edit_line add_users_information_to_inventory(userlist)
{
insert_lines:
"<USER>${userlist}</USER>$(const.n)" location => after_users,
comment => "Add the UUID and CFKEY tags in the inventory file";
}
#Locators
body location after_location(pos) {
select_line_matching => ".*$(pos).*";
before_after => "after";
}
body location after_deviceid {
select_line_matching => ".*<DEVICEID>.*";
before_after => "after";
}
body location after_content {
select_line_matching => ".*<CONTENT>.*";
before_after => "after";
}
body location after_vm {
select_line_matching => ".*<VMS>.*";
before_after => "after";
}
body location after_users {
select_line_matching => ".*<USERSLIST>.*";
before_after => "after";
}
###############
# Editors
##############
# Convert a simple list in <VM TYPe="vmtype"><NAME>machine_name</NAME><UUID>value<UUID></VM>
bundle edit_line xmlify(ATTR) {
replace_patterns:
"\"(.*)\" \{(.*)\}"
replace_with=> xmled($(ATTR));
}
body replace_with xmled(attribute) {
replace_value => "<VM TYPE=\"$(attribute)\"><NAME>$(match.1)</NAME><UUID>$(match.2)</UUID></VM>";
}
# select the inventory files that has the right extension
#I'd like to select also those older than 4 hours (ctime => irange(ago(0,0,0,4,0,0),now);) not working...
# (for some reason, ocs duplicated files over time)
body file_select inventory_files {
(windows|linux|android)::
leaf_name => { ".*.ocs" };
file_result => "leaf_name";
#windows::
# leaf_name => { ".*.xml" };
# file_result => "leaf_name";
}
body perms inventory_perms
{
mode => "0700";
}
body file_select one_day_age
#
# we can build old "include", "exclude", and "ignore"
# from these as standard patterns - these bodies can
# form a library of standard patterns
#
{
mtime => irange(ago(1,0,0,0,0,0),ago(0,0,1,0,0,0));
file_result => "mtime";
}