Wednesday, March 12, 2008

TEC: Ensuring User Predicates Load

One of the best features of the Tivoli Enterprise Console is the ability to create custom Prolog predicates that are callable from within event processing rules. The Prolog source can be loaded into the TEC environment using either the consult/* built-in or the user_predicates file in TEC_TEMPLATES. The tricky part is verifying that your custom Prolog actually compiles and loads when TEC start, as the only indication you get is things break...

Here is a mechanism to test and alert if a Prolog source file in TEC_TEMPLATES does not load.

Refer to the Rule Builder's Guide for instructions of implementing your custom Prolog from the TEC_TEMPLATES directory. This article will assume that you already have created your source files and have a valid TEC_TEMPLATES/user_predicates file.

The compile and load process does funny things to your Prolog source. When a rule base is loaded, the files are copied to $DBDIR/tec/rb_dir and the compile process seems to translate the Prolog source file into FILENAME.rls.pro so we will have to take this into account when we check to see if the file is loaded.

In BIM Prolog you can check if a Prolog file has been loaded using the current_file/1 built-in. If the argument to current_file/1 is a free variable then the predicate will backtrack and provide a list of every file that is loaded in the environment. If you use a ground variable then the predicate will only succeed if the specified file is loaded.

So to check the files loaded from TEC_TEMPLATES we will have to give the full path and tack on the .rls.pro to end of the file name. Here is a simple reception action to perform the checks and generate an event when a file is not loaded.



reception_action:check_custom_predicate_load:
(
_templates_dir = '$DBDIR/tec/rb_dir/TEC_TEMPLATES',
re_user_predicates(_file),
sprintf(_path,'%s/%s.rls.pro',[_templates_dir,_file]),
not(current_file(_path)),
sprintf(_msg,
'User predicate file TEC_TEMPLATES/%s was not loaded.',
[_file]),
generate_event('TEC_Error',[ hostname=_hostname,
severity='CRITICAL',
source='TEC',
msg=_msg])

)


The same basic method can be used to check any consulted Prolog file, but you will have explicitly check each file you tried to consult.

No comments: