netiquslaie Absent Member.
Absent Member.
1964 views

Problem using custom.js to assign values to CustomerVars

Hello,

I'm been banging my head against this for the past couple of days but no luck. I'm trying to enhance one of our collectors to find events that match a particular regex and for events that match, I want to grab a value and assign it to a CustomerVar value. Here's my custom.js (took out comments):

Collector.prototype.customInit = function() {
return true;
};

Record.prototype.customPreParse = function(e) {
return true;
};

Record.prototype.customParse = function(e) {
this.parseCustomField(e);
return true;
};

Record.prototype.parseCustomField = function(e) {
this.s_RXBufferString.search(/GET\s+.*(\d+));
this.CustomerVar021 = RegExp.$1;
return true;
};


I verified that substring is in s_RXBufferString and the collector is in "custom" Execution mode.

I uploaded the file and looked to make sure the custom.js was deployed in that collector instance but still no luck getting that subexpression plugged into the cv21 value.

Can anyone advise as to what I might be doing wrong? I didn't think I needed to add in a custom map if I was using the long name, but I did have an earlier version of the file where I tried that as well.
0 Likes
11 Replies
Knowledge Partner
Knowledge Partner

Re: Problem using custom.js to assign values to CustomerVars

Are you using the debugger to see if the custom method is called, or if
after customparse exists the record object ("this" in many contexts, but
not all) has the variable set? If you do not map the variable to a
Sentinel field then you may not see it later, but you should still see the
variable set on the record while the collector is working on that record
(via the debugger).


--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...
0 Likes
Micro Focus Expert
Micro Focus Expert

Re: Problem using custom.js to assign values to CustomerVars

On 25.01.2017 17:26, netiquslaie wrote:
>
> Hello,
>
> I'm been banging my head against this for the past couple of days but no
> luck. I'm trying to enhance one of our collectors to find events that
> match a particular regex and for events that match, I want to grab a
> value and assign it to a CustomerVar value. Here's my custom.js (took
> out comments):


The code you poseted is in all UPPERCASE. That won't work. JavaScript is
case sensitive.

>
> COLLECTOR.PROTOTYPE.CUSTOMINIT = FUNCTION() {
> RETURN TRUE;
> };
>
> RECORD.PROTOTYPE.CUSTOMPREPARSE = FUNCTION(E) {
> RETURN TRUE;
> };
>
> RECORD.PROTOTYPE.CUSTOMPARSE = FUNCTION(E) {
> THIS.PARSECUSTOMFIELD(E);
> RETURN TRUE;
> };
>
> RECORD.PROTOTYPE.PARSECUSTOMFIELD = FUNCTION(E) {
> THIS.S_RXBUFFERSTRING.SEARCH(/GET\S+.*(\D+));
> THIS.CUSTOMERVAR021 = REGEXP.$1;


You either need to assign a value to e.CustomerVar21 or extend the
Rec2Evt map so that CUSTOMERVAR021 maps to a field (see
https://www.novell.com/developer/plugin-sdk/collector_customization.html)

--
Norbert
0 Likes
brandon-langley Absent Member.
Absent Member.

Re: Problem using custom.js to assign values to CustomerVars

klasen;2449517 wrote:
On 25.01.2017 17:26, netiquslaie wrote:
>
> Hello,
>
> I'm been banging my head against this for the past couple of days but no
> luck. I'm trying to enhance one of our collectors to find events that
> match a particular regex and for events that match, I want to grab a
> value and assign it to a CustomerVar value. Here's my custom.js (took
> out comments):


The code you poseted is in all UPPERCASE. That won't work. JavaScript is
case sensitive.

>
> COLLECTOR.PROTOTYPE.CUSTOMINIT = FUNCTION() {
> RETURN TRUE;
> };
>
> RECORD.PROTOTYPE.CUSTOMPREPARSE = FUNCTION(E) {
> RETURN TRUE;
> };
>
> RECORD.PROTOTYPE.CUSTOMPARSE = FUNCTION(E) {
> THIS.PARSECUSTOMFIELD(E);
> RETURN TRUE;
> };
>
> RECORD.PROTOTYPE.PARSECUSTOMFIELD = FUNCTION(E) {
> THIS.S_RXBUFFERSTRING.SEARCH(/GET\S+.*(\D+));
> THIS.CUSTOMERVAR021 = REGEXP.$1;


You either need to assign a value to e.CustomerVar21 or extend the
Rec2Evt map so that CUSTOMERVAR021 maps to a field (see
https://www.novell.com/developer/plugin-sdk/collector_customization.html)

--
Norbert


it shows lowercase if you're reading it from the web browser (well, it does for me +Chrome). Maybe a side effect of a tag in your reader?
0 Likes
brandon-langley Absent Member.
Absent Member.

Re: Problem using custom.js to assign values to CustomerVars

netiquslaie;2449489 wrote:
Hello,

I'm been banging my head against this for the past couple of days but no luck. I'm trying to enhance one of our collectors to find events that match a particular regex and for events that match, I want to grab a value and assign it to a CustomerVar value. Here's my custom.js (took out comments):

Collector.prototype.customInit = function() {
return true;
};

Record.prototype.customPreParse = function(e) {
return true;
};

Record.prototype.customParse = function(e) {
this.parseCustomField(e);
return true;
};

Record.prototype.parseCustomField = function(e) {
this.s_RXBufferString.search(/GET\s+.*(\d+));
this.CustomerVar021 = RegExp.$1;
return true;
};


I verified that substring is in s_RXBufferString and the collector is in "custom" Execution mode.

I uploaded the file and looked to make sure the custom.js was deployed in that collector instance but still no luck getting that subexpression plugged into the cv21 value.

Can anyone advise as to what I might be doing wrong? I didn't think I needed to add in a custom map if I was using the long name, but I did have an earlier version of the file where I tried that as well.


Your issue is here:

this.s_RXBufferString.search(/GET\s+.*(\d+));


You did not close the regex....it should be this (although I haven't tested):

this.s_RXBufferString.search(/GET\s+.*(\d+)/);


One mechanism I use that will force the compiler to outright break (although I'm surprised that didn't break it) is to pass the string to the regex, especiall for simple extractions like your use case:

/GET\s+.*(\d+)/.test(this.s_RXBufferString)


It also keeps me mentally honest because it won't feel right to put the .test right after the capture statement.
0 Likes
netiquslaie Absent Member.
Absent Member.

Re: Problem using custom.js to assign values to CustomerVars

Yes, thanks about the hint for closing the regex. I was actually following the example they gave on our Collector Customization webpage:

/**
* This method parses custom fields from the event
* @param {Event} e The output event, passed in so you can call methods like e.add2EI()
*/
Record.prototype.parseCustomField = function(e) {
this.s_RXBufferString.search(/Critcality=(\S*));
// You also need to add a new mapping for CustomerVar78 in an extension to Rec2Evt.map, see above
this.cv78 = RegExp.$1;
return true;
};


I think I did try modifying the custom.js to put in the closing slash later and it still didn't work...

I was using CustomerVar021 instead of CustomerVar21 because 021 is what shows up for the long name in the Tips field in the WebUI.

Let me go in and make those 2 changes to the custom.js though and I'll get back to you.

Thanks to everyone! I'll report back shortly 🙂
0 Likes
netiquslaie Absent Member.
Absent Member.

Re: Problem using custom.js to assign values to CustomerVars

So I changed it to this:

Record.prototype.parseCustomField = function(e) {
this.s_RXBufferString.search(/GET\s+.*(\d+)/);
this.CustomerVar21 = RegExp.$1;
return true;
};


Still no love...
0 Likes
Knowledge Partner
Knowledge Partner

Re: Problem using custom.js to assign values to CustomerVars

Did you do the mapping of the variable to an event field as mentioned
previously? Alternatively try just assigning something without using a
regex to see that it works at all:


Record.prototype.parseCustomField = function(e) {
//this.s_RXBufferString.search(/GET\s+.*(\d+)/);
//this.CustomerVar21 = RegExp.$1;
this.CustomerVar21 = "testing data here";
return true;
};



--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...
0 Likes
netiquslaie Absent Member.
Absent Member.

Re: Problem using custom.js to assign values to CustomerVars

Eureka, I had to put this in:

e.CustomerVar21 = RegExp.$1

I think you were trying to tell me that, Norbert, but I missed the "e" part 🙂

Thanks!
0 Likes
Knowledge Partner
Knowledge Partner

Re: Problem using custom.js to assign values to CustomerVars

On 01/25/2017 02:56 PM, netiquslaie wrote:
>
> Eureka, I had to put this in:
>
> e.CustomerVar21 = RegExp.$1
>
> I think you were trying to tell me that, Norbert, but I missed the "e"
> part 🙂


Just some thoughts on this to help understand the process.

For some reason back in the day (Sentinel 6.0 when ECMAScript became an
option for collector) the way that was recommended for getting attributes
onto the Event object, and thus into Sentinel, was to setup variables on
the Record object flowing through the collector by assigning instance
variables to the current "this" object. Once all processing was done, the
system would use the Rec2Evt.map file to identify which variables on the
record would be mapped to the event and, once set, the event would be sent
through Sentinel. Hooray!

Fast forward a few years, it seems to be a bit overkill when it is just as
possible o write directly to the Event object ('e') and skip the need for
the Rec2Evt.map part later on; maybe it even performs very-slightly
faster, though I've not tested it and it would almost certainly be very
slight. Still, if you forget to use Rec2Evt.map to get things from the
record to the event, you can bypass that entirely by just writing to
e.<ValidSentinelVariableNameHere> within the collector's ECMAScript. Be
careful to not mix the two too much or you could end up with something
written in ECMAScript and then overwritten later by the mapping, or so I
think, and that would be pretty confusing.

At the end of the day the record is discarded and all that matters is the
event, and the event must have its variables set with proper Sentinel
event field names or else they do not get seen by the rest of the system.

--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...
0 Likes
netiquslaie Absent Member.
Absent Member.

Re: Problem using custom.js to assign values to CustomerVars

That makes sense. Thanks for the explanation! I'm able to get things working in my environment now...
0 Likes
brandon-langley Absent Member.
Absent Member.

Re: Problem using custom.js to assign values to CustomerVars

ab;2449537 wrote:
On 01/25/2017 02:56 PM, netiquslaie wrote:
>
> Eureka, I had to put this in:
>
> e.CustomerVar21 = RegExp.$1
>
> I think you were trying to tell me that, Norbert, but I missed the "e"
> part 🙂


Just some thoughts on this to help understand the process.

For some reason back in the day (Sentinel 6.0 when ECMAScript became an
option for collector) the way that was recommended for getting attributes
onto the Event object, and thus into Sentinel, was to setup variables on
the Record object flowing through the collector by assigning instance
variables to the current "this" object. Once all processing was done, the
system would use the Rec2Evt.map file to identify which variables on the
record would be mapped to the event and, once set, the event would be sent
through Sentinel. Hooray!

Fast forward a few years, it seems to be a bit overkill when it is just as
possible o write directly to the Event object ('e') and skip the need for
the Rec2Evt.map part later on; maybe it even performs very-slightly
faster, though I've not tested it and it would almost certainly be very
slight. Still, if you forget to use Rec2Evt.map to get things from the
record to the event, you can bypass that entirely by just writing to
e.<ValidSentinelVariableNameHere> within the collector's ECMAScript. Be
careful to not mix the two too much or you could end up with something
written in ECMAScript and then overwritten later by the mapping, or so I
think, and that would be pretty confusing.

At the end of the day the record is discarded and all that matters is the
event, and the event must have its variables set with proper Sentinel
event field names or else they do not get seen by the rest of the system.

--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...


You are correct, Rec2Event is processed after the event has passed all the normal processes and is ready to send. So you definitely want to avoid overlap.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.