-
1. Re: How to read .txt file values placed from a Linux Server by a TPL pattern
Adam KerrisonFeb 27, 2015 7:03 AM (in response to SANDEEP BHATIA)
1 of 1 people found this helpfulFrom TPL you can use discovery.fileGet() to retrieve the content of a file. Extracting the values can done using regex.extract() on the file.content attribute
-
2. Re: How to read .txt file values placed from a Linux Server by a TPL pattern
George Sheehey Mar 3, 2015 12:45 PM (in response to SANDEEP BHATIA)1 of 1 people found this helpfulHi Sandeep - we do this with the following (see attached) TPL which reads a flat file located under /etc.
-
3. Re: How to read .txt file values placed from a Linux Server by a TPL pattern
George Sheehey Mar 3, 2015 12:45 PM (in response to George Sheehey)tpl 1.6 module USCC_Compliance;
// *****************************************************************************************
// This pattern is a sample pattern. This pattern may be used in whole or in part
// as part of an ADDM implementation, however it is in itself supported in the same way
// as patterns written by the end user.
//
// Whoever uses this pattern assumes responsibility for the deployment as if they had
// written the pattern themselves.
// ******************************************************************************************
// Names surrounded by angle brackets, and prefixed by double dollar
// signs like <$$pattern_name> should all be replaced with values
// suitable for the pattern. The replacement should replace everything
// inside the enclosing less-than, greater-than INCLUDING the less-than,
// greater-than characters themselves.
//
// Text prefixed with // like these lines are comments that extend to
// the end of the line.
//
configuration ComplDiscCfg 1.0
"""Set Configuration options to control location of Compliance File Discovery"""
"Common Unix File Locations"
common_locations := ["/etc/uscc-release"];
end configuration;
pattern USCC_Compliance 1.0
"""
This pattern does some additional discovery of a UNIX Server.
"""
// Optional metadata section containing information about the
// product(s) identified by this pattern. Each entry should be a
// comma-separated list of strings.
metadata
// More metadata attributes may be set as required
products := "Inventory";
publishers := "USCC";
categories := "Asset";
end metadata;
// Required overview section. Some tags must be defined. Tags are
// comma-separated lists of identifiers, e.g.:
//
// overview
// tags database, example_pattern;
// end overview;
overview
tags USCC;
end overview;
// Optional constants section used here to declare the type of
// SoftwareInstance being created.
constants
type := "USCC ASSET & COMPLIANCE DATA";
force_pci := "Other";
end constants;
// Required triggers section. The unix_cmd prefix builds a regular
// expression suitable for identifying Unix commands; windows_cmd
// builds a regular expression suitable for identifying Windows
// commands. For a general regular expression, use regex as the
// prefix.
triggers
on host := Host created, confirmed where os_class = "UNIX";
end triggers;
// Required body section. Finds the Host node corresponding to the
// process so its name can be used, then creates or updates a group
// SoftwareInstance that counts the number of instances on the host.
body
log.info ("USCC_Compliance: entry");
instance := "";
//DEBUG INFO - Enable if needed (GJS)
//cmdres := discovery.runCommand(host,"cat /etc/uscc-release");
//if cmdres and cmdres.result then
// log.debug ("Tag:CAT-RESULT%cmdres.result%");
//end if;
for location in ComplDiscCfg.common_locations do
log.debug ("USCC_Compliance: Looking in directory %location%");
instance_file := discovery.fileGet(host, location);
if instance_file and instance_file.content then
log.debug ("USCC_Compliance: Found the file.");
build_date := "";
built_by := "";
rc_number := "";
environment := "";
maintenance_window := "";
pci_control := "";
sox_control := "";
primary_application := "";
primary_application_owner := "";
facility := "";
pci_flag := "";
build_date := regex.extract(instance_file.content, regex 'build_date=(.*)', raw '\1');
built_by := regex.extract(instance_file.content, regex 'built_by=(.*)', raw '\1');
rc_number := regex.extract(instance_file.content, regex 'rc_number=(.*)', raw '\1');
environment := regex.extract(instance_file.content, regex 'environment=(.*)', raw '\1');
maintenance_window := regex.extract(instance_file.content, regex 'maintenance_window=(.*)', raw '\1');
pci_control := regex.extract(instance_file.content, regex 'pci_control=(.*)', raw '\1');
sox_control := regex.extract(instance_file.content, regex 'sox_control=(.*)', raw '\1');
primary_application := regex.extract(instance_file.content, regex 'primary_application=(.*)', raw '\1');
primary_application_owner := regex.extract(instance_file.content, regex 'primary_application_owner=(.*)', raw '\1');
facility := regex.extract(instance_file.content, regex 'facility=(.*)', raw '\1');
log.debug("USCC_Compliance: Extracted data from the file");
// ADD a new detail to the host node
key := "%instance% %host.hostname%";
name := "%host.hostname% - %location%";
detail := model.Detail(
key := key,
name := type,
type := name,
build_date := build_date,
built_by := built_by,
rc_number := rc_number,
environment := environment,
maintenance_window := maintenance_window,
pci_control := pci_control,
sox_control := sox_control,
primary_application := primary_application,
primary_application_owner := primary_application_owner,
facility := facility,
pci_flag := pci_flag);
// Relate detail to Host Detail:Detail:ElementWithDetail:Host
log.debug("HostChassis: Relating Detail to Host");
model.rel.Detail(Detail := detail , ElementWithDetail := host);
else
log.debug("USCC_Compliance: No file found in this directory.");
end if;
end for;
end body;
end pattern;
-
4. Re: How to read .txt file values placed from a Linux Server by a TPL pattern
Maurizio ZaccariaMar 4, 2015 3:55 AM (in response to SANDEEP BHATIA)
Hi Sandeep,
please could you share your tpl to read from an xml file?
thanks
Maurizio
-
5. Re: How to read .txt file values placed from a Linux Server by a TPL pattern
SANDEEP BHATIA Mar 4, 2015 5:29 AM (in response to George Sheehey)Hi George
I am new to TPL, Its bit confusing for me to design, I have below path and values with fields.
apps/LOB.txt
Support Team :="ABC"
Primary Application :="XYZ"
And this is what I build
// UNIX Server Asset Registration Pattern
tpl 1.5 module UNIX_AssetReg;
metadata
origin := "Custom";
tree_path := "Server Enrichment", "UNIX Asset Registration";
end metadata;
pattern UNIXAssetReg 1.0
'''
Target: Pattern pulls server asset registration data from UNIX .txt file placed in /apps/LOB.txt and populates them in ADDM.
Details:The taxonomy has been extended (via 'asset_registration.xml' in the ~tideway/data/custom/taxonomy directory
'''
overview
tags UNIX, AssetRegistration;
end overview;
constants
type := "UNIX ASSET REGISTRATION";
type := "NoLOBData";
end constants;
triggers
on host := Host created, confirmed where type matches "UNIX";
end triggers;
body
log.info ("UNIX_AssetReg: entry");
instance := "";
LOB := regex.extract(instance_file.content, regex 'LOB=(.*)', raw '\1');
if LOB then
host.Support Team := LOB.value;
else host.Support Team := NoLOBData;
endif
if LOB then
host.Primary Application := LOB.value;
else host.Primary Application := NoLOBData;
endif
end body;
end pattern;
-
6. Re: How to read .txt file values placed from a Linux Server by a TPL pattern
Jonas Lindholm Mar 4, 2015 6:51 AM (in response to SANDEEP BHATIA)Sandeep, I don't see that your TPL pattern call getFile to populate variable instance_file.
Also, your pattern says in a comment that you updated the taxonomy, there should be no need to do that at all for the simple task you wants to do, what exactly did you do with the taxonomy?
The TPL language is like any other scripting programing language, it just have a few more limitations than others but it works the same way.
-
7. Re: How to read .txt file values placed from a Linux Server by a TPL pattern
Adam KerrisonMar 4, 2015 7:10 AM (in response to SANDEEP BHATIA)
You are missing the call to actually get the file. In the pattern body before the LOB := regex.extract() call you need something like this:
instance_file := discovery.fileGet(host, '/apps/LOB.txt');
if not instance_file then
log.error("Failed to get /apps/LOB.txt");
stop;
end if;
This tells ADDM to retrieve the file so you can process the content. You need to check that this is successful as ADDM might fail to retrieve if (the file doesn't exist, ADDM doesn't have permission to read it etc)
-
8. Re: How to read .txt file values placed from a Linux Server by a TPL pattern
George Sheehey Mar 4, 2015 11:18 AM (in response to SANDEEP BHATIA)1 of 1 people found this helpfulHi Sandeep - If you were to load my pattern that I posted into ADDM as I posted it and then add the following flat file under /etc directory, and then scan the host you will get an idea of how it reads the file and adds it to the details of the host node in ADDM.
$ cat uscc-release
# /etc/uscc-release file
# Standard Inventory Management file
# Version 1.0
discover_date=
build_date=
built_by=
rc_number=
environment=
maintenance_window=
sox_control=
pci_control=
primary_application=
primary_application_owner=
serial_number=
support_contract=
facility=
location=
-
9. Re: How to read .txt file values placed from a Linux Server by a TPL pattern
SANDEEP BHATIA Mar 4, 2015 12:03 PM (in response to Jonas Lindholm)Hi Jonas
Via custom taxonomy. I simply added some additional fields than usual DDD data where ADDM already picking values from Windows Registery. So there is no registery kind of standard in Linux. So my Linux team is going to create a .txt file from where I want to pick values & add in ADDM where OS="UNIX".
-
10. Re: Re: How to read .txt file values placed from a Linux Server by a TPL pattern
Jonas Lindholm Mar 4, 2015 1:12 PM (in response to SANDEEP BHATIA)I still don't understand why you would need to modify the taxonomy because all you script does is to add two new attributes. There is no need to modify the taxonomy when all you want to do is to add new attributes to a node in ADDM.
-
11. Re: How to read .txt file values placed from a Linux Server by a TPL pattern
SANDEEP BHATIA Mar 26, 2015 8:25 AM (in response to Jonas Lindholm)Hey
We already have a pattern developed to pick values from registery, so have permanently added some fields like Support team, business contacts etc for each server. thats why custom taxonomy, so if any field dont have values I can see them blank and can ask teams to fill those to be compliant from Asset Registration point of view.
Hope this clarify.
Sandeep
-
12. Re: How to read .txt file values placed from a Linux Server by a TPL pattern
Robert Karin Jul 18, 2017 7:23 AM (in response to SANDEEP BHATIA)Hi Bahatia,
I 'm new in this area. So please if you can attach me last version of TPL file what you wrote for LOB.txt for Linux machine.
Dou you uploaded this tpl in Manage > Knowledge Modzule: Custom tpl.
If you share me your experience with custom TPL what I need to do step by step that I can discoverd this file
and succesiful sync to cmdb?
Relationship make automaticly with CI or I musr to do custom for this?
thank you in advance
Robert
-
13. Re: How to read .txt file values placed from a Linux Server by a TPL pattern
George Sheehey Jul 18, 2017 9:18 AM (in response to Robert Karin)Hi Bahatia
I added the TPL we use to read a flat named "uscc-release" file located under /etc/. The flat file is created when the Unix Admins build-out the server and then ADDM reads it during scan and adds the data as a "Detail" node for the host.
Hope this helps
-
USCC_Compliance.tpl 7.5 K
-
-
14. Re: How to read .txt file values placed from a Linux Server by a TPL pattern
Robert Karin Jul 18, 2017 1:38 PM (in response to George Sheehey)Hi George,
thanks you for your tpl filee, please if you can attach me your file uscc-release that I can test in my environment.
Thanks
Robert