You are not logged in.
Pages: 1
If you want to create a batch file that does the above, all you need to do is add an extra "%" into the batch file. for example:
for /L %%n in (1,1,10) do copy test.xml XmlOut\Test%%n.xml
This is only possible if you are using an xml file signal registry. In this example we will use the name "test.xml" as our trigger file.
Firstly you need to open the windows command prompt.
Next "cd" into the directory that contains your test file. e.g.
cd SXI/XPress
Once in the correct directory you can use the below command:
for /L %n in (1,1,10) do copy test.xml XmlOut\Test%n.xml
This command is used to copy a file into another directory as many times as is specified and rename that file with an incrementing number at the end. In the above example it will copy the file "test.xml" into the XmlOut directory 10 times with an incrementing digit up to 10. e.g. test1.xml, test2.xml, test3.xml, etc.
If you wanted to copy the file into XmlOut 200 times you would change the command as follows:
for /L %n in (1,1,200) do copy test.xml XmlOut\Test%n.xml
If the from address needs to change per transaction you can also change it in the "DataDefinition", this will overwrite whatever is configured in the SMTP Connector.
Add the following field to the "DataDefinition":
<sxi:Field name="NA">
<sxi:Rules>
<sxi:Default>Sender.name@Flintstones.com</sxi:Default>
</sxi:Rules>
<sxi:OutputField>From</sxi:OutputField>
</sxi:Field>
You could also remove the default rule and use an object in memory.
One way to add attachments is to have the file you want to attach stored on the local storage drive, then just add the following to the "DataDefinition":
<sxi:Field name="NA">
<sxi:Rules>
<sxi:Concatenation>
<sxi:Delimiter/>
<sxi:Fields>
<sxi:Field staticValue="yes">X:\ATTACHMENT\FILE\PATH\</sxi:Field>
<sxi:Field>//*[local-name()='AttachmentFileName']</sxi:Field>
</sxi:Fields>
</sxi:Concatenation>
</sxi:Rules>
<sxi:OutputField datatype="file_attachment">Attachment</sxi:OutputField>
</sxi:Field>
The field containing "AttachmentFileName" is useing an object in memory with the files name.
Negative lookahead is used when you want to match something not followed by something else. We use this to find the last occurrence of a word in a string.
You can test all the below using Regex101.
The Regex looks as follows:
Word1(?!.*Word2)
"Word1" and "Word2" can be replaced with the relevant strings.
The regex finds the "Word1" you want to match and looks ahead in the string to see if "Word2" is found. If "Word2" is found it will not match. For example:
This Word1 will not match, because Word2 is ahead of it. However this Word1 will match.
This means If "Word1" and "Word2" are the same in the regular expression the last occurrence will match.
Example regex 1:
Test(?!.*Test)
Example Test String:
This Test must not match, however this Test should match.
The reason the first "Test" does not match is because "Test" is ahead of it. However the last "Test" matches because there is no "Test" ahead of it in the string.
Multiple line Negative Lookahead
If there is a line break multiple matches could be made, because the above regex works on a line to line basis.
If there is a multi line string use the following regex:
Example regex 2:
(?s:.*\s)\KTest(?!.*Test)
NB* I would recommend always using Example regex 2 because you can also use it for a single line string.
Example regex 2 does the same as Example regex 1, however it works for multi line strings. For example:
This Test must not match.
Neither should this Test.
This Test will match.
Requirements for running the SXIWebServices in Docker:
Install Docker
Follow the steps to download docker from this link based on your operating system.
Go to docker settings on your local machine and perform the following:
For Windows go to docker settings and on the "Daemon" tab click on the advanced toggle switch and add the following to the json given:
"insecure-registries": ["xlayer.co.za:5000"]
For Linux edit the "daemon.json" file. The default location is "/etc/docker/daemon.json". (If the file cannot be found, create it.) then add the following code:
{
"insecure-registries" : ["xlayer.co.za:5000"]
}
To download the docker image and run it, perform the following:
For Windows in an administrator CMD execute the following command:
docker run -p 8080:8080 -d --name SXIWebService -v C:/SXI/XPress/XmlOut:/opt/SXI/XPress/XmlOut -v C:\SXI\WebServiceLogs:/opt/SXI/WebServiceLogs xlayer.co.za:5000/sxiws:2.1
For Linux in a terminal execute the following command:
sudo docker run -p 8080:8080 -d --name SXIWebService -v /opt/SXI/XPress/XmlOut:/opt/SXI/XPress/XmlOut -v /opt/SXI/WebServiceLogs:/opt/SXI/WebServiceLogs xlayer.co.za:5000/sxiws:2.1
A short explanation:
"-v C:/SXI/XPress/XmlOut:/opt/SXI/XPress/XmlOut -v C:\SXI\WebServiceLogs:/opt/SXI/WebServiceLogs"
The above argument mounts a directory on your local computer with a directory in the container. The parts highlighted in red point to the directory on your local computer. The parts highlighted in blue point to the directory in the container.
NB* if any of the directories highlighted in red do not exist you will get an ERROR. Make sure they are pointing to the correct folder path that exists. Remember that the above example is for Windows however the same applies for Linux as well.
After performing these steps Tomcat will be up and running and all SXI web services will be available. You can access them by pointing your browser to "localhost:8080/SXIWebServices-2.1/". The default user of the manager-gui for Tomcat is "sxi" and the password is our standard password.
If the X-EventCollector logs give an error that looks as follows:
00:00:00.000 - TRACE - Successfully opened the mail folder Inbox to search for mails matching the given search terms
00:00:00.000 - ERROR - TimerTask execution failed unexpectedly: null
java.lang.StackOverflowError: null
at javax.mail.search.AndTerm.match(AndTerm.java:109)
at javax.mail.search.AndTerm.match(AndTerm.java:109)
at javax.mail.search.AndTerm.match(AndTerm.java:109)
at javax.mail.search.AndTerm.match(AndTerm.java:109)
at javax.mail.search.AndTerm.match(AndTerm.java:109)
If you restart the X-EventCollector service it should work again. The cause of this is that X-EventCollector used more memory then it was CONFIGURED to.
To change this configuration go to the "SXI\X-EventCollector\bin" directory and edit a file named "X-EventCollector.vmoptions".
The contents of the file will look as follows:
# Enter one VM parameter per line
# For example, to adjust the maximum memory usage to 512 MB, uncomment the following line:
# -Xmx512m
# To include another file, uncomment the following line:
# -include-options [path to other .vmoption file]
Uncomment the 3rd line that contains "# -Xmx512m" by removing the "#" and then adjust the amount of memory that X-EventCollector can use. e.g. from "512m" to "1024m" (1gb).
Once the above steps are completed restart the X-EventCollector service and it should work.
This is an example of how to write a file to disk from a base64 string in memory.
You will need the following connector:
<Connector id="WriteFile" type="FileSystem">
<Connection xsi:type="sxi:FileSystem">
<sxi:Write>
<sxi:SaveLocation>C:\Path\Where\File\Will\Be\Saved</sxi:SaveLocation>
<sxi:FileName>$FileName$</sxi:FileName>
</sxi:Write>
</Connection>
<sxi:ReturnCodes>
<sxi:Success/>
<sxi:RecoverableError/>
</sxi:ReturnCodes>
</Connector>
Notice that the FileName is between two "$" (This will be changed to "~#~" in a future release) this indicates that "FileName" is a field in memory that will be used when a file is created. You could also put in a static value here by removing the "$"'s.
You can use a "MemoryDataManipulation" to set the "FileName" for the connector. For Example:
<sxi:DataDefinition name="SetFileName">
<sxi:Fields>
<sxi:Field name="na">
<sxi:Rules>
<sxi:Default>Fred.txt</sxi:Default>
</sxi:Rules>
<sxi:OutputField>FileName</sxi:OutputField>
</sxi:Field>
</sxi:Fields>
</sxi:DataDefinition>
Where I have "na" you could also use an field in memory with a valid file name and file extension.
Next you need to create the file using this mapping:
<Create dataDefinition="WriteFileToDisk" connectorId="WriteFile" source="C:\Path\Where\File\Will\Be\Saved"/>
The "source" attribute is the path where the file will be written. If you make the source "na" the path in the connector will be used.
The DataDefinition "WriteFileToDisk" looks as follows:
<sxi:DataDefinition name="WriteFileToDisk">
<sxi:Fields>
<sxi:Field name="mData">
<sxi:OutputField datatype="base64">FileContents</sxi:OutputField>
</sxi:Field>
</sxi:Fields>
</sxi:DataDefinition>
"mData" is the field in memory containing the base64 we want to write to a file.
"OutputField" must contain the attribute datatype="base64"
The "Outputfield" for the "mData" MUST be the word FileContents.
When this action is run the filesystem connector will create a file "fred.txt" in the following path "C:\Path\Where\File\Will\Be\Saved".
In this example we will be using 3 computers.
The IP Address for the computers are as follows:
Computer A : 10.0.0.1
Computer B : 10.0.0.2
Computer C : 10.0.0.3
We want to send "Computer B" a file from "Computer A", but if "Computer B" is down we will send the file to "Computer C".
The Destination in the file we want to send should contain both possible destinations separated by a ";" with the preferred destination first.
similar to this:
<XPress>
<Destination>10.0.0.2;10.0.0.3</Destination>
</XPress>
Our Dispatch routing table for "Computer A" should look as follows:
<?xml version='1.0' encoding='UTF-8' ?>
<RoutingTable xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.sxi.co.za/XMLSchema/XPress/Dispatch"
xmlns:sxi="http://www.sxi.co.za/XMLSchema"
xsi:schemaLocation="http://www.sxi.co.za/XMLSchema/XPress/Dispatch ../schema/RoutingTable.xsd">
<route ValidDest="localhost" NextHop="localhost"/>
<route ValidDest="10.0.0.2" NextHop="10.0.0.2"/>
<route ValidDest="10.0.0.3" NextHop="10.0.0.3"/>
</RoutingTable>
With this if "Computer B" is down the file will be sent to "Computer C".
In answer to the above post point 2:
2. The source is not referring to the name of the sheet, but rather the sheet number.
So for example, if you had 3 sheets and named the first one "info" in source you would still use "Sheet1" in the source attribute in the collect mapping.
The "DateConverter" can also be used to input the current date in the format that you define in the "<OutputDateFormat>" attribute.
To do this however, the attribute "<InputDateFormat>" MUST be empty.
E.g
<sxi:DateConverter InputDateFormat="" OutputDateFormat="dd-MM-yyyy"/>
"MaxFileSize" is used to limit the size of the output file that gets created.
Below is example config for the "EventCollector":
<Event name="">
<Transmission>
<Destination></Destination>
<EndpointOutPlugin></EndpointOutPlugin>
<MaxFileSize></MaxFileSize>
</Transmission>
<Traps>
<Trap entryPoint="">
</Trap>
</Traps>
</Event>
When configuring the "Event" one of the required fields in the "Transmission" element is "<MaxFileSize>". The number you input will be in bytes.
E.g if you configure as follows:
<MaxFileSize>10</MaxFileSize>
The output xml file will NOT be created if the total size is greater then 10 bytes.
If we configure like this:
<MaxFileSize>0</MaxFileSize>
The file will be created no matter how big it is.
This rule combines separate strings with a customisable delimiter.
Example:
Street= “20 Peltier Dr”
Suburb= “Sunninghill”
PostalCode= “2191”
We will use the above elements to create a single element called "Address".
<sxi:Field name="na">
<sxi:Rules>
<sxi:Concatenation>
<sxi:Delimiter>, </sxi:Delimiter>
<sxi:Fields>
<sxi:Field>Street</sxi:Field>
<sxi:Field>Suburb</sxi:Field>
<sxi:Field>PostalCode</sxi:Field>
</sxi:Fields>
</sxi:Concatenation>
</sxi:Rules>
<sxi:OutputField>Address</sxi:OutputField>
</sxi:Field>
Notice the "<sxi:Field name="na">" does not need a value as you wont need any information from it.
After using the above config "Address" will look as follows:
Address = "20 Peltier Dr, Sunninghill, 2191"
IMPORTANT:
if you want to use the Concatenation "sxi:Field" as a normal string(not an element), use the "staticValue" attribute.(See attributes below for more info)
Example:
<sxi:Field name="na">
<sxi:Rules>
<sxi:Concatenation>
<sxi:Delimiter>, </sxi:Delimiter>
<sxi:Fields>
<sxi:Field staticValue="yes">Street</sxi:Field>
<sxi:Field staticValue="yes">Suburb</sxi:Field>
<sxi:Field staticValue="yes">PostalCode</sxi:Field>
</sxi:Fields>
</sxi:Concatenation>
</sxi:Rules>
<sxi:OutputField>Address</sxi:OutputField>
</sxi:Field>
this config will make "Address" look as follows:
Address = "Street, Suburb, PostalCode"
Attributes:
staticValue:
If set to yes it will use the "Field"s configuration as a string not as an element.
This rule changes the format of the given date to one you specify.
Example:
Date= “15/03/2019”
The above "Date" is in a dd/MM/yyyy format, we want to change the format to yyyy-MM-dd.
<sxi:Field name="//*[local-name()=’Date’]">
<sxi:Rules>
<sxi:DateConverter InputDateFormat="dd/MM/yyyy" OutputDateFormat="yyyy-MM-dd"/>
</sxi:Rules>
<sxi:OutputField>Date</sxi:OutputField>
</sxi:Field>
After using the above config "Date" will look as follows:
Date = "2019-03-15"
You can also use "DateConverter" for time.
To see examples of pattern syntax follow the link bellow (found at the bottom of the article):
https://www.journaldev.com/17899/java-s … ate-format
Attributes:
InputDateFormat:
The format that is being used as the input.
OutputDateFormat:
The format that is expected.
This rule will Split a string into separate elements inside objects in memory.
Example:
Address= “20 Peltier Dr, Sunninghill, 2191”
We want to Split the text whenever there is a , so that we can get a street , suburb and postal-code.
<sxi:Field name="//*[local-name()=’Address’]">
<sxi:Rules>
<sxi:Split>
<sxi:Delimiter>,</sxi:Delimiter>
<sxi:OutputFields>
<sxi:OutputField index="0">Street</sxi:OutputField>
<sxi:OutputField index="1">Suburb</sxi:OutputField>
<sxi:OutputField index="2">PostalCode</sxi:OutputField>
</sxi:OutputFields>
</sxi:Split>
</sxi:Rules>
<sxi:OutputField>Address</sxi:OutputField>
</sxi:Field>
After using the above config this is what will be stored in memory:
<Address>20 Peltier Dr, Sunninghill, 2191</Address>
<Street>20 Peltier Dr</Street>
<Suburb>Sunninghill</Suburb>
<PostalCode>2191</PostalCode>
Attributes:
index:
The split creates an array of elements separated by the delimiter. Each element of this array is identified by the index attribute.
number:
If number is set to "yes" then the string is split on the number of characters you specified.
This rule will remove any excess characters from a string.
Example:
Text = “This string should end here (), but it keeps going.”
We want to cut the text when it gets to this point "()"
<sxi:Field name="//*[local-name()=’Text’]">
<sxi:Rules>
<sxi:Length>30<sxi:Length>
</sxi:Rules>
<sxi:OutputField>Text</sxi:OutputField>
</sxi:Field>
After using the above config "Text" will now look as follows:
Text = “This string should end here ()”
Attributes:
removeElements:
If this attribute is set to yes and the value of the sting is over the given length the entire string will be removed.
This is a very simple rule to remove every character in a string except numbers.
EXAPMLE:
Text = “1a 2b 3c”
Notice there are spaces and letters in "Text".
<sxi:Field name="//*[local-name()=’Text’]">
<sxi:Rules>
<sxi:RemoveNonNumeric/>
</sxi:Rules>
<sxi:OutputField>Text</sxi:OutputField>
</sxi:Field>
After using the above config the text will now look like this:
Text = 123
I have 2 fields that i collected previously called "realname" and "value". I want to send these fields in an email.
The SMTP Connector looks as follows:
<Connector id="SMTPEmail" type="SMTP">
<Connection xsi:type="sxi:SMTP">
<sxi:Server>smtp.gmail.com</sxi:Server>
<sxi:User>ofi@sxi.co.za</sxi:User>
<sxi:Password>XXXXXX</sxi:Password>
<sxi:RetryDelay>60</sxi:RetryDelay>
<sxi:AuthType>SSL</sxi:AuthType>
<sxi:Port>465</sxi:Port>
<sxi:FromAddress>ofi@sxi.co.za</sxi:FromAddress>
</Connection>
<sxi:ReturnCodes>
<sxi:Success />
<sxi:RecoverableError />
</sxi:ReturnCodes>
</Connector>
"Server" is the name of the SMTP mail server where the connection will be made.
"User" must contain the username used to authenticate with the SMTP server.
"Password" for the above mentioned user. NOTE: The password must not contain an @ sign.
"AuthType" is set to SSL. The "Port" must be 465, otherwise if AuthType is set to TLS the "Port" must be 587. It's easier to use SSL as TLS needs additional configuration.
"FromAddress" is the email address where the email will be sent from.
I have a "Create" mapping that looks as follows:
<Create dataDefinition="DetailsToSendEmail" connectorId="SMTPEmail" source="na"/>
The DataDefinition to use with SMTP must have the following output fields:
To
Subject
Body
The full DataDefinition will look as follows:
<sxi:DataDefinition name="DetailsToSendEmail">
<sxi:Fields>
<sxi:Field name="na">
<sxi:Rules>
<sxi:Default>recipient.name@acme.com</sxi:Default>
</sxi:Rules>
<sxi:OutputField datatype="recipients">To</sxi:OutputField>
</sxi:Field>
<sxi:Field name="Subject">
<sxi:Rules>
<sxi:Concatenation>
<sxi:Delimiter> </sxi:Delimiter>
<sxi:Fields>
<sxi:Field staticValue="yes">Person:</sxi:Field>
<sxi:Field>realname</sxi:Field>
<sxi:Field staticValue="yes">Was Queried.</sxi:Field>
</sxi:Fields>
</sxi:Concatenation>
</sxi:Rules>
<sxi:OutputField>Subject</sxi:OutputField>
</sxi:Field>
<sxi:Field name="Body">
<sxi:Rules>
<sxi:Concatenation>
<sxi:Delimiter> </sxi:Delimiter>
<sxi:Fields>
<sxi:Field staticValue="yes">Person's real name =</sxi:Field>
<sxi:Field>realname</sxi:Field>
<sxi:Field staticValue="yes">
Value returned =</sxi:Field>
<sxi:Field>value</sxi:Field>
</sxi:Fields>
</sxi:Concatenation>
</sxi:Rules>
<sxi:OutputField>Body</sxi:OutputField>
</sxi:Field>
</sxi:Fields>
</sxi:DataDefinition>
Because i don't have a recipient in memory and I always want to send to "recipient.name@acme.com" I just add a default to the required output field called To and the datatype must be recipients as seen below:
<sxi:Field name="na">
<sxi:Rules>
<sxi:Default>recipient.name@acme.com</sxi:Default>
</sxi:Rules>
<sxi:OutputField datatype="recipients">To</sxi:OutputField>
</sxi:Field>
As you can see I used the Concatenation Rule to populate both my subject and body.
<sxi:Field name="Subject">
<sxi:Rules>
<sxi:Concatenation>
<sxi:Delimiter> </sxi:Delimiter>
<sxi:Fields>
<sxi:Field staticValue="yes">Person</sxi:Field>
<sxi:Field>realname</sxi:Field>
<sxi:Field staticValue="yes">Was Queried.</sxi:Field>
</sxi:Fields>
</sxi:Concatenation>
</sxi:Rules>
<sxi:OutputField>Subject</sxi:OutputField>
</sxi:Field>
<sxi:Field name="Body">
<sxi:Rules>
<sxi:Concatenation>
<sxi:Delimiter> </sxi:Delimiter>
<sxi:Fields>
<sxi:Field staticValue="yes">Person's real name =</sxi:Field>
<sxi:Field>realname</sxi:Field>
<sxi:Field staticValue="yes">
Value returned =</sxi:Field>
<sxi:Field>value</sxi:Field>
</sxi:Fields>
</sxi:Concatenation>
</sxi:Rules>
<sxi:OutputField>Body</sxi:OutputField>
</sxi:Field>
This will result in an email that looks like this:
From: ofi@sxi.co.za
To: recipient.name@acme.com
Subject: Person Fred Flintstone was queried.
Body:
Person's real name = Fred Flintstone
Value returned = 1500
Remember when editing "install-service-metricbeat.ps1" to change displayName to X-ServerMonitor on line 13 and change line 14 as follows:
-path.data `"C:\SXI\Dashboard\metricbeat\Data`" -path.logs `"C:\SXI\Dashboard\metricbeat\logs`
Pages: 1