Introduction
Symantec provides an Administrator Software Development Kit (ASDK) that contains standard method to access or create some of the Symantec Management Platform and Solutions items programatically.
But from time to time customers or partners need to just query the database in order to get some data out (for example in the case of the Patch Trending tool or other {CWoC} utilities I published here on Connect). This can be handled directly from the program or framework standpoint, however such programming put the burden on the customer in term of security and code maintenance.
This download present a Database API that taps on the existing SMP code infrastructure and as such inherit security features from the platform, such as a the AdminDatabaseContext (which requires the users running the program to be part of the Symantec Administrator group) and automatic linking to the Symantec CMDB (regardless of customised names).
Presenting the API
The API is kept to the simplest possible form: a DLL that provides a single public static method that execute the SQL query passed to it as a string and returns a System.Data.SqlClient.DataTable type to the caller.
Here is a formal definition of the API:
Namespace: Symantec.CWoC; Class name: DatabaseAPI Class members: n/a Class methods: public static System.Data.SqlClient.DataTable GetTable(System.string);
The API is built using SMP 7.1 SP2 MP1.1 and ties to Altiris.NS.dll version 7.1.8400, however it is compatible with version 7.5, 7.5 SP1 as we have policies in place to bind to the latest version of the assembly available.
Download details
This download, much like the API itself is rather simple. 2 file in a zip container, precisely:
File name: DatabaseAPI.dll File size: 3,584 bytes SHA256: FB5DA745613EBF7FB1F5EF7E53C3172A6677A86CA24D9800F847FC60AA335428
Consuming the code
Here is a quick sample that comsumes the DatabaseAPI dll and prints out 10 computer names and domain names from the vComputer table
using System; using System.Data; using System.Data.SqlClient; using Symantec.CWoC; class sample { public static void Main() { string sql = "select top 10 name, domain from vComputer"; DataTable t = DatabaseAPI.GetTable(sql); foreach (DataRow r in t.Rows) { Console.WriteLine("Computer: {0}, domain: {1}.", r[0], r[1]); } } }
Compiling
The compilation process is a little more complex than usual, but nothing that could not be handled from memory ;-).
Save the sample code provided above as "sample.cs" in the same folder you uncompressed the DLL and run:
csc /reference:DatabaseAPI.dll sample.cs
Note! csc in this case referes to a batch (csc.bat) that resides in the %windir% and that point to the .net compiler program you want to use, in most cases one of these 2 files and passes command line arguments to the called programs (as %*):
- %windir%\Microsoft.NET\Framework\v2.0.50727\csc.exe %*
- %windir%\Microsoft.NET\Framework64\v2.0.50727\csc.exe %$
This will produce a .net executable (32 or 64-bit depending on the version of csc you are using) that you can now take to your SMP (if you compiled on your local workstation but this is not a requirement) and run. It should output something like:
Computer: hal-9000, domain: odissey.space.a.2001 Computer: hal-9001, domain: odissey.space.a.2001 Computer: hal-9002, domain: odissey.space.a.2001 Computer: hal-9003, domain: odissey.space.a.2001 Computer: hal-9100, domain: odissey.space.a.2001 Computer: hal-9200, domain: odissey.space.a.2001
Hopefully you will have more than 6 computers on your DB but this should allow you to start building some quick and easy program to solve specific problms that cannot be addressed by a product targetting a large audience, such as the SMP and its suites of solutions.