Friday, January 13, 2012

How to Use Poll Instance Properties in a View

If you aren't completely, 100% comfortable with manipulating the database manually, stop reading this post now.  If you continue reading this post, you do so at your own risk.

In NV (and NPC if you've jailbroken it), you can create views using the NV Custom View Wizard.  One of the things the developers did but didn't really publicize is that you can pull poll instance properties into those views.  This includes any custom properties you may have added to the poll instance.  By default all poll instances have at least two properties: 'Name' and 'Description'.  Built in dataset poll instances (like ifstats) will have other properties which you can also use.  The trick is that you have to manipulate the database slightly in order to instruct the view to even look at the properties.  It isn't too bad, but like I said before, if you don't know how to do this with your eyes closed, don't try it.
  1. First you have to get the control id of the view (technically called a control) you have just created and will be modifying.  This is pretty easy to get, just open the view in the wizard and look in the url for the controlid parameter.  In this example, the id is 1200031.
  2. Next you need to get into the database and take a look at the control properties for your control.  Something like this: 'select * from control_properties where controlid=1200031 order by pageid, propertiesid, userid, propertyname;'
That should result in something like the following.

ControlID PageID PropertiesID UserID PropertyName PropertyType PropertyValue Editable Enabled
1200031 0 0 0 ColumnNames string latencymin,latencyaverage,latencymax Y Y
1200031 0 0 0 ControlType string PollInstance Y Y
1200031 0 0 0 Create.Date string Added at 1/13/2012 9:05:07 AM by nqadmin Y Y
1200031 0 0 0 data.chartType string Table Y Y
1200031 0 0 0 DataSetName string ISILONPerf Y Y
1200031 0 0 0 Description string This report focuses on the worst values for the specified parameter and therefore may be more prone to problems or failure. Y Y
1200031 0 0 0 DisplayFormats string ms|ms|ms Y Y
1200031 0 0 0 DisplayNames string Minimum,Average,Maximum Y Y
1200031 0 0 0 string Y Y
1200031 0 0 0 FieldNames string latencymin;latencyaverage;latencymax Y Y
1200031 0 0 0 FieldNames2 string Y Y
1200031 0 0 0 FieldNames3 string Y Y
1200031 0 0 0 FieldNames4 string Y Y
1200031 0 0 0 FieldNames5 string Y Y
1200031 0 0 0 Filepath string /nqWidgets/Poller/wptTopN.ascx Y Y
1200031 0 0 0 footer.text string Y Y
1200031 0 0 0 Limit string 10 Y Y
1200031 0 0 0 MibTables string ISILON_MIB.nodeProtocolPerfEntry Y Y
1200031 0 0 0 OrderBy string latencyaverage DESC Y Y
1200031 0 0 0 PropertyNames string Description,Name Y Y
1200031 0 0 0 RedThreshold string Y Y
1200031 0 0 0 Title string Isilon Node Performance Table by Protocol Y Y
1200031 0 0 0 Wizard.Action string ReportWizard('/npc/ReportWizard.aspx?PageID={PageID}&CtrlID={CtrlID}&PropertiesID={PropertiesID}'); Y Y
1200031 0 0 0 yaxis2.ColumnNames string Y Y
1200031 0 0 0 yaxis2.DisplayColors string Y Y
1200031 0 0 0 yaxis2.DisplayFormats string Y Y
1200031 0 0 0 yaxis2.DisplayNames string Y Y
1200031 0 0 0 YellowThreshold string Y Y

  1. You'll notice that I have a property called PropertyNames.  This is the entry you need to add to this table.  The propertyname will be 'PropertyNames' as shown.  The propertyvalue will be a comma separated list of the properties you would like to be available to this view.  For example, since I want both the description and the name properties available to this view, I added them both in there.
    You would normally add this record using an insert SQL statement.  A 0 in the pageid, propertyid, and/or userid fields represents a wildcard.  Technically, a view can exist multiple times on a page.  If it does, the pageid will contain the id of the page on which the control instance(s) exist(s).  The propertyid refers to which instance of the view on the page.  The userid refers to any properties that the user may have modified and saved to only their account.  If you want this change to apply to all instances of the view, the easiest would be to make the change to the default (pageid=0, propertyid=0, userid=0) then re-customize any views that have been customized.
  2. Once you've got that done, you can go back to the view wizard.  Go to the 4th step.  You can now use the property values within expressions or the 'Where' field.  The syntax is as follows: p_PropertyName.property_value, where PropertyName is the name from the comma separated list you entered into the database.  In my case, if I wanted to display the description, I would create an expression called 'Description' and the expression formula would be 'p_Description.property_value'.
One of the nice things about exposing properties is that you can use the properties in the 'Where' field of the view.  The where field allows you to pre-filter the view so that only certain objects show up.  For example, if I knew that the description contained an enumerated set of values (cifs, nfs, http, other), I could create a view that only shows the cifs objects by putting "p_Description.property_value = 'cifs'" in the Where field.

Unfortunately, this doesn't work for device properties like sysLocation, sysContact, sysName, sysObject, etc.  However, there is a script floating around that will take those parameters and store them in custom poll instance properties, which could then be exposed using this method.

No comments:

Post a Comment