I'm testing a simple HostToLocation pattern that goes like this:
tpl 1.12 module Videotron_Pattern_Location; metadata origin := "Videotron"; tree_path := "Videotron", "Pattern", "Extension", "Location"; end metadata; table LocationIdToName 1.0 "LOC1" -> "Montréal - Place Bonaventure - LAB"; "LOC2" -> "Montréal - Patate"; // Arrange that any value that is lookup up for which there isn't an entry // is given as the none value. default -> none; end table; pattern HostToLocation 1.0 """ This is a template pattern for linking NetworkDevices to Locations based on device name. """ // Required overview section. Some tags must be defined. overview tags Videotron, Pattern, Host, Location; end overview; // We trigger whenever a Host is created for the first time, or confirmed on // a subsequent discovery run. triggers on host := Host created, confirmed; end triggers; body // Extract location id from the host name. e.g. to extract the first two // characters, use a regular expression of "^(..)". if host.name = 'slbsaportald1' then location_id := 'LOC1'; log.debug("location_id: %location_id%"); end if; // Look up the location name from the table location_name := LocationIdToName[location_id]; log.debug("location_name: %location_name%"); if not location_name then // Unknown location stop; end if; // Find the Location node(s) for the location location := search(Location where name = %location_name%); log.debug("location: %location%"); if not location then log.debug("No location found"); // No node for this location? stop; end if; // Relate host to location. Using "uniquerel" rather than "rel" means that // any existing Location relationships between this Host (the first // parameter) and any Location nodes other than the one given (the second // parameter) are removed. If a host has changed location, this keeps the // model up-to-date. model.uniquerel.Location( ElementInLocation := host, Location := location ); end body; end pattern;
I have created the corresponding locations in the Location categories, but when I run the pattern against a group to test it, I get this debug output:
slbsaportald1 (0): 481ms: location_id: LOC1
slbsaportald1 (0): 481ms: location_name: MontrÃ©al - Place Bonaventure - LAB
slbsaportald1 (0): 483ms: No location found
slbsaportald1 (0): 483ms: location: <reasoning.lowlanguage.nodesetproxy.NodeSetProxy object at 0x7f5347071910>
The pattern has been properly saved in UNIX end of line format and UTF-8 encoding. I have typed the characters manually and they were not pasted from clipboard.
How can I get this to work? It seems the character encoding/decoding is not done properly.
If I search for it using a manual query, it works:
search Location where name = 'Montréal - Place Bonaventure - LAB'