Miscellaneous Ramblings on Hacking

July 6, 2016

Shared Connection Info

Filed under: Uncategorized — Zack Bethem @ 8:44 pm

One of the common problems in a production environment relies on having a shared connection information between all of the scripts that operate in that environment. In searching for a solution, I developed the following approach for our maintenance scripts written in VBScript.

For all connection information, a common XML file is created that stores all connection information. This file is then protected using the appropriate controls within the operating system. The structure is similar to a App.config for Web.config file for most .Net solutions.

<?xml version="1.0">
<appSettings>
 <!-- db connection settings -->
 <rmdbconnection key="rmDbConnection" value="DSN=MART;UID=userDatabase;PWD=userPassword;" /> 
</appSettings>

Then, from the VB script, the database connection can be retrieved via the following function:

Function retrieveDBConnection( sPasswordFile, sNodeName )

 'parse dbpassword file and get connectivity info
 Set objXML = CreateObject("MSXML2.DOMDocument")
 objXML.Async = False
 objXML.Load(sPasswordFile)

 'find root node &lt;appSettings&gt;
 Set node = objXML.documentElement.selectSingleNode("/appSettings")

 ' check to see that the root node was found, if not throw a quit
 if node is nothing then
 WScript.Quit 1
 else
 for each xNode in node.childNodes
 if xNode.nodename = sNodeName then

 Dim atttr
 for each attr in xNode.attributes
 
 'cycling through each attribute name, find the 'value' attribute
 if attr.name = "value" then
 
 'return the found 'value' attribute
 retrieveDBConnection = attr.text 
 end if
 next
 end if
 next 
 end if

End Function

The above can then be called via the snippet:

'validate existence of password file
if filesys.FileExists(sPasswordFile) then
 WScript.Echo FormatDateTime(Now(),0) &amp; vbTab &amp;"Password file found, proceeding.."
 'parse dbpassword file and get connectivity info
 sODBC = retrieveDBConnection(sPasswordFile, "rmdbconnection" )
else
 WScript.Echo FormatDateTime(Now(),0) &amp; vbTab &amp;"Missing required password file for database connectivity."
 WScript.Quit 1
end if
Advertisements

December 7, 2015

VisualStudio shortcuts by version

Filed under: Uncategorized — Zack Bethem @ 2:20 am

Awesome sauce here.

http://visualstudioshortcuts.com/2013/

May 19, 2013

Querying SQL Server (and DB2) for table sizes

Filed under: Uncategorized — Zack Bethem @ 4:30 pm

Found this gem and I MUST save it for future reference.

http://www.mssqltips.com/tip.asp?tip=1177

For the DB2 equivalent:

select t.tabname, t.tabschema, type
, (DATA_OBJECT_P_SIZE + INDEX_OBJECT_P_SIZE + LONG_OBJECT_P_SIZE + LOB_OBJECT_P_SIZE + XML_OBJECT_P_SIZE)/1024 as TOTAL_SIZE_IN_MB
from syscat.tables as t, sysibmadm.admintabinfo as a
where t.tabname=a.tabname and t.tabname like 'UAC_%'
order by (DATA_OBJECT_P_SIZE + INDEX_OBJECT_P_SIZE + LONG_OBJECT_P_SIZE + LOB_OBJECT_P_SIZE + XML_OBJECT_P_SIZE) desc
fetch first 20 rows only

May 23, 2012

SVN version into your Assembly.cs file

Filed under: Uncategorized — Zack Bethem @ 8:10 pm

I wanted an incrementing Assembly version, but I didn’t want to have to do it manually. Some quick Googling and I found this nice solution:

I’ve been using SubWCRev that’s in the TortoiseSvn installation (I think it’s downloadable seperately too).
First i create a “template”-file for the AssemblyInfo.cs called AssemblyInfo.cs.in
This is created as a copy of the exisiting one.
Then replace the parts you want changed with SubWCRev placeholders like this:
[assembly: AssemblyVersion(“1.2.3.$WCREV$”)]
Then create a PreBuildEvent to run SubWCRev with appropriate parameters:
SubWCRev <wcpath> AssemblyInfo.cs.in AssemblyInfo.cs
Done.

So, this is translated as follows:

  • my AssemblyInfo template file AssemblyInfo.cs.in reads as follows:
// Version Notes:
// Updated to 2.0.0 for .net4 switch over
[assembly: AssemblyVersion("2.0.0.$WCREV$")]
[assembly: AssemblyFileVersion("2.0.0.$WCREV$")]

 

  • And I tweaked the PreBuildEvent in VisualStudio to use Macros.. it reads as follows:
subwcrev $(ProjectDir) $(ProjectDir)\Properties\AssemblyInfo.cs.in $(ProjectDir)\Properties\AssemblyInfo.cs

 

Fun stuff indeed.

September 27, 2011

Getting Started: Unica Marketing Operations’ Custom Triggers

Filed under: Uncategorized — Zack Bethem @ 2:52 pm

You have the SDK. You have the JavaDocs. There are samples, but how does it all glue together? This post is all about writing your first UMO custom trigger. These triggers help to automate tasks or enforce business rules within UMO.

What you Need?

A few needed items:

  • Unica Marketing Operations (UMO) environment
  • Eclipse IDE for EE
  • Associated JARs: affinium_plan.jar, log4j.jar

The JARs are best grabbed from the UMO environment.

Start Eclipse & Code

Startup Eclipse and create a new Application Client Project. This project template option is available under the Java EE folder.

Capture2

Set the JDK to the same level as the web application server that UMO is deployed on. I selected 5.0 for JDK 1.5.

Here I define my AutoReviewerAssignment class. All triggers are required to implement the IProcedure interface.

   1:  

   2: public class AutoReviewerAssignment implements IProcedure {

   3:  

   4:     // The Name and Description of this Procedure.

   5:     private static final String name           = "AutoReviewerAssignment";

   6:     private static final String desc           = "Provides automatic assignment of reviewers based on project member assignment";

   7:     private static final PluginVersion pv        = new PluginVersion(1, 0, 0); 

   8:       

   9:     // Constants

  10:     private static final String DEBUG          = "debug";

  11:     private static final int    STATUS_SUCCESS = 0;

  12:     private static final int    STATUS_FAILED  = -1;

  13:     

Unica products use Log4J for all system logging. There are a couple of products in the Unica suite that don’t, but it’s a safe bet that log4j is being used. For UMO, it is. I’m getting the logger and setting it to a static variable. This way I can add my own class’ log entries to the main log file.

   1: //added - latch on to the log4j logger

   2:     private static final Logger _LOG = Logger.getLogger(AutoReviewerAssignment.class);

   3:     

The interface defines some standard methods, the first of importance is the initialize() method. This is your time to grab some site specific parameters. In some cases, I’ve grabbed from a standard Java .properties file. But Unica also provides the ability to define these parameters in the actual procedure definition file  where the procedure is declared (more on this later).

   1: public void initialize(Map initParams) throws PluginInitializationException {

   2:         // TODO Auto-generated method stub

   3:         _LOG.info("Initializing class trigger procedure..");

   4:         

   5:         //only expecting one init parameter

   6:         if(initParams.containsKey(DEBUG))

   7:         {

   8:             try{

   9:                 isDebug = ((Boolean) initParams.get(DEBUG)).booleanValue();

  10:                 _LOG.debug("Debug mode is enabled: " + String.valueOf(isDebug));

  11:             } catch(Exception e)

  12:             {

  13:                 _LOG.fatal("Exception in initialization. "+ e.getMessage());

  14:                 throw new ProcedureInitializationException("Problem using init parameter: DEBUG");

  15:             }

  16:         }

  17:     }

Finally, there’s the execute method. This is where the action happens and is unique to your own implementation goals.

Configuration Deployment

Once compiled, it’s time to migrate the compiled class file for your procedure. Here’s the steps:

  • Review the [PLAN_HOME]\conf\plan_config.xml to ascertain the environment’s configuration. We’re looking for the following UAPInitParams: integrationProcedureDefinitionPath and integrationProcedureClasspathURL
  • integrationProcedureDefinitionPath points to a procedure_plugins.xml file. This file defines the class, including the initialization parameters. Here’s an example:
   1: <procedure>

   2:     <key>POCtest</key>

   3:     <class-name>com.amberleaf.procedure.POCtest</class-name>

   4:     <init-parameters>

   5:     <init-parameter>

   6:       <param-name>debug</param-name>

   7:       <param-type>java.lang.Boolean</param-type>

   8:             <param-value>true</param-value>

   9:     </init-parameter>

  10:     </init-parameters>

  11: </procedure>

  • integrationProcedureClasspathURL points to the directory where the resulting class file should be placed
  • Finally, bounce the web application server so that the new class can be cached

Now that the environment is setup, it’s time to define the actual trigger. This defines when the trigger should actually fire within Unica Marketing Operations. To do this, we go to: Settings > Marketing Operations Settings > Trigger Bindings.

  • Click ‘Add New Trigger Binding’
  • Define the trigger with the appropriate attributes:

Capture

For example, my trigger would be limited to the ‘Project’ marketing object. The trigger would be limited to the context of ‘People’. Put another way, the trigger would be limited to the ‘People’ tab under the ‘Project’ object. I then further limit the trigger to only execute on the ‘Updated’ event. In summary, the trigger will fire when the ‘People’ tab of a ‘Project’ is ‘Updated’.

And there you have it. You’ve created your first trigger. A special note here. Since we latched on to the log4j logger of Unica’s, we will see our logging entries in the Unica Marketing Operation’s system log. Just be sure to set your log4j logging level appropriately.

March 3, 2011

Best Summary for String.Format Ever

Filed under: Uncategorized — Zack Bethem @ 3:20 am

Perfect.

http://www.csharp-examples.net/string-format-datetime/

July 9, 2010

Pimp your Eclipse!

Filed under: Uncategorized — Zack Bethem @ 6:30 pm

Props to the dark theme creator for a better looking Eclipse.

http://blog.prabir.me/post/Dark-Eclipse-Theme.aspx

May 26, 2010

Outlook Barfing on GMAIL via IMAP

Filed under: Uncategorized — Zack Bethem @ 5:56 pm

No idea what happened, but found that Outlook wouldn’t send anymore messages via GMAIL IMAP. I found this little morsel and viola… problem fixed.

http://theofficecubicle.com/2008/02/01/outlook-2003-red-x-where-embedded-image-should-be-in-email/

  1. Exit out of Outlook 2003 on the machine with the issue
  2. Open the registry (Start->Run->type cmd->click Ok)
  3. Navigate and open the following registry key HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Security\OutlookSecureTempFolder
  4. Within the key…it should say something like  %USERPROFILE%\Local Settings\Temporary Internet Files\OLK3D\
  5. Highlight and delete %USERPROFILE%\Local Settings\Temporary Internet Files\OLK3D\
  6. Close out of the registry and open Outlook 2003!
  1. Exit out of Outlook 2003 on the machine with the issue
  2. Open the registry (Start->Run->type cmd->click Ok)
  3. Navigate and open the following registry key HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Security\OutlookSecureTempFolder
  4. Within the key…it should say something like  %USERPROFILE%\Local Settings\Temporary Internet Files\OLK3D\
  5. Highlight and delete %USERPROFILE%\Local Settings\Temporary Internet Files\OLK3D\
  6. Close out of the registry and open Outlook 2003!

February 11, 2010

Querying SQL Server for Table sizes

Filed under: Uncategorized — Zack Bethem @ 9:23 pm

Found this gem and I MUST save it for future reference.

http://www.mssqltips.com/tip.asp?tip=1177

BEGIN try 
DECLARE @table_name VARCHAR(500) ; 
DECLARE @schema_name VARCHAR(500) ; 
DECLARE @tab1 TABLE(
tablename VARCHAR (500) collate database_default
,       schemaname VARCHAR(500) collate database_default
); 
DECLARE  @temp_table TABLE (    
tablename sysname
,       row_count INT
,       reserved VARCHAR(50) collate database_default
,       data VARCHAR(50) collate database_default
,       index_size VARCHAR(50) collate database_default
,       unused VARCHAR(50) collate database_default 
); 
INSERT INTO @tab1 
SELECT t1.name
,       t2.name 
FROM sys.tables t1 
INNER JOIN sys.schemas t2 ON ( t1.schema_id = t2.schema_id );   
DECLARE c1 CURSOR FOR 
SELECT t2.name + '.' + t1.name  
FROM sys.tables t1 
INNER JOIN sys.schemas t2 ON ( t1.schema_id = t2.schema_id );   
OPEN c1; 
FETCH NEXT FROM c1 INTO @table_name;
WHILE @@FETCH_STATUS = 0 
BEGIN  
        SET @table_name = REPLACE(@table_name, '[',''); 
SET @table_name = REPLACE(@table_name, ']',''); 
-- make sure the object exists before calling sp_spacedused
IF EXISTS(SELECT OBJECT_ID FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(@table_name))
BEGIN
                INSERT INTO @temp_table EXEC sp_spaceused @table_name, false ;
END
        FETCH NEXT FROM c1 INTO @table_name; 
END; 
CLOSE c1; 
DEALLOCATE c1; 
SELECT t1.*
,       t2.schemaname  insert into temp_table_sizes

FROM @temp_table t1 
INNER JOIN @tab1 t2 ON (t1.tablename = t2.tablename )
ORDER BY  schemaname,tablename;
END try 
BEGIN catch 
SELECT -100 AS l1
,       ERROR_NUMBER() AS tablename
,       ERROR_SEVERITY() AS row_count
,       ERROR_STATE() AS reserved
,       ERROR_MESSAGE() AS data
,       1 AS index_size, 1 AS unused, 1 AS schemaname 
END catch

I followed it up with the following modification, however:

select *, cast(substring(data,1, charindex(' ',data,1)-1)/1024/1024 as decimal) as data_GB from temp_table_sizes order by cast(substring(data,1, charindex(' ',data,1)-1) as integer) desc , row_count desc

December 22, 2009

Fun with Unica Easysets

Filed under: Uncategorized — Zack Bethem @ 3:42 am

I don’t feel like looking this up everytime.. so here it is.

Problem

ETL finishes and you need to automate the refresh of your Unica easysets in CustomerInsight.

Solution

This dos script does the work.. yeah that’s right.. so sexy it is! DOS.

@echo off
@echo "Refreshing Customer EasySet"
e:
cd e:\unica\Insight
nettracker customer -update
@echo "Customer Easyset refresh complete"
@echo
@echo "Refreshing Sales EasySet"
nettracker bintest -update
@echo "Sales EasySet refresh complete"
@echo "Refreshing Response EasySet"
nettracker responses -update
@echo "Response Easyset refresh complete"
@echo on

Some things of note. The script is updating three easysets of the name: customer, bintest, and responses. This is their system name and not the “friendly” name.

Older Posts »

Create a free website or blog at WordPress.com.