Pattern Designer model_id

AchimM279672093
Tera Contributor

Hello,

I would like to set the model for an SNMP device in Pattern Designer.

I can read the model via sysdescr, but I can’t enter this value directly under $cmdb_ci_ip_switch[*].model_id. To do that, I would need to know the model_id.
This is, of course, difficult because the model may not have existed previously, and even if it did, I can’t find a way to determine the model_id in Pattern Designer.

Unfortunately, the Pattern Designer does not have the MakeAndModelJS function, as is available for probes/sensors.

Does anyone know of a way to enter the model in plain text?

I would appreciate a response.

 

Best regards,
Achim

8 REPLIES 8

@thomasbueck 

I was able to extract the model using the pattern from the SNMP sysdescr. However, I can't write this value to the model_id field because it expects a sys_id there. In the video you mentioned, this is done without a sys_id, but it doesn't show whether it actually works. I doubt it does. I’d like to stick with the pattern, since that’s probably the way of the future, but there’s no way to call MakeAndModelJS (I get errors in EVAL) or an alternative method that replaces MakeAndModelJS.

I’m aware of the pre/post scripts, but I haven’t implemented them yet. I also don’t know how to use the variables/values determined in the pattern in the post script afterward.

Has anyone done this before?
Used MakeAndModelJS in pre/or post scripts with parameter passing from the pattern?

thomasbueck
Giga Contributor

@AchimM279672093 Pre and post scripting is standard it's ootb and it will always be used as EVAL has it's limitations.
If you copy and modify the logic of an existing script it's pretty easy. There are several scripts which are using MakeAndModelJS - you can search for it and use the logic.
In the script you have the payload, f.e. this pattern: "Handle Model and Manufacturer for EMC Isilon"

This is the script:

var payloadObj = JSON.parse(payload);

var populateManufacturerAndModelDetails = function() {
    if (payloadObj.hasOwnProperty('items')) {
        var payloadItems = payloadObj.items;
        var manufacturer, model;
        for (var i = 0; i < payloadItems.length; i++) {
            if (payloadItems[i].className.includes('cmdb_ci_storage_cluster')
                || payloadItems[i].className.includes('cmdb_ci_storage_node_element')
                || payloadItems[i].className.includes('cmdb_ci_storage_server')
                || payloadItems[i].className.includes('cmdb_ci_disk')) {
                manufacturer = payloadItems[i].values.manufacturer;
                model = payloadItems[i].values.model_id;
                var makeAndModel = global.MakeAndModelJS.fromNames(manufacturer, model, 'hardware');
                if (!gs.nil(makeAndModel.getManufacturerSysID()))
                    payloadItems[i].values.manufacturer = makeAndModel.getManufacturerSysID();
                if (!gs.nil(makeAndModel.getModelNameSysID()))
                    payloadItems[i].values.model_id = makeAndModel.getModelNameSysID();
            }
        }
    }
populateManufacturerAndModelDetails();
 
You loop through the payload items and via .attributeName you can get and set the values
You only need to add your pattern under "Patterns" that ServiceNow knows when your script needs to run.

Give it a try - I was surprised how smooth it worked.

Kind Regards
Thomas

 

AchimM279672093
Tera Contributor

Yes, thats what I saw already.  All scripts, which are using  MakeAndModelJS are Pre scripts. Maybe I'm wrong, but I need it in a Post script, because I calculate/read the actual model only in the pattern, i.e. after the Pre phase. Otherwise, I’d have to read the model from sysdescr via JavaScript to set it in the Pre script. That would probably work too, but the Pattern Designer is more convenient for this. Gerne würde ich das Post Script benutzen.

thomasbueck
Giga Contributor

@AchimM279672093 Was the same for me, but Pattern Designer has it's limitations and a pre script worked fine.
From my experience, pre-script runs after the pattern designer, but for the save.
I could use the data, which I fetched in a custom step.
Don't forget: Probieren geht über studieren 😉