MSBuild Paramaters.xml xpath appsettings file attribute - visual-studio-2010

Im using msbuild to create a web deploy package using the parameters.xml file to replace web.config settings.
Im trying to replace the appsettings file attribute in web.config
This is my parameters.xml:
<parameter name="ClientConfig" description="Please enter the clients config file name." defaultValue="Niad.config" tags="">
<parameterEntry kind="XmlFile" scope="\\web.config$" match="/configuration/appSettings/setting[#name='file']/value" />
</parameter>
This is my Web.config section:
<?xml version="1.0"?>
<configuration>
<appSettings file="Client.config">
</appSettings>
</configuration>
I know I'm writing the xpath match incorrectly, I was hoping someone could help me with the correct syntax.

This worked:
match="/configuration/appSettings/#file"
<parameter name="ClientConfig" description="Please enter the clients config file name." defaultValue="Niad.config" tags="">
<parameterEntry kind="XmlFile" scope="\\web.config$" match="/configuration/appSettings/#file" />
</parameter>

Related

OpenNMS implement script to get status of any service

I am trying to implement script(sh, py..) that will get mi True(Up) of False(Down) status if my installed app on nodes is up-to-date.
Before that, i tried to implement simple script found on net (https://wiki.opennms.org/wiki/SystemExecuteMonitor) just to see if script works.
OpenNMS is installed on Windows 10.
This is what i did so far:
In poller-configuration.xml
`<service name="Test" interval="300000" user-defined="false" status="on">
<parameter key="script" value="/etc/scripts/test.sh"/>
<parameter key="banner" value="OK"/>
<parameter key="retry" value="3"/>
<parameter key="timeout" value="3000"/>
<parameter key="rrd-repository" value="/opt/opennms/share/rrd/response"/>
<parameter key="ds-name" value="test"/>
</service>`
AND
`<monitor service="Test" class-name="org.opennms.netmgt.poller.monitors.SystemExecuteMonitor"/>`
In default-foreign-source.xml
`<detector name="Test" class="org.opennms.netmgt.poller.monitors.SystemExecuteMonitor">
<parameter key="script" value="/etc/scripts/test.sh"/>
<parameter key="banner" value="OK"/>
<parameter key="retry" value="3"/>
<parameter key="timeout" value="3000"/>
<parameter key="rrd-repository" value="/opt/opennms/share/rrd/response"/>
<parameter key="ds-name" value="test"/>
</detector>`
And this is what i am missing: snmpd.conf
I don't have that file in OpenNMS, so my question is where should i call that script to be executed and do i miss anything else to get this working?
Thnx!
In the meantime, i've implemented groovy script like this:
In poller-configuration.xml
<service name="MinGroovy" interval="300000" user-defined="true" status="on">
<parameter key="file-name" value="C:/OpenNMS/etc/scripts/MinimalGroovy.groovy"/>
<parameter key="bsf-engine" value="org.codehaus.groovy.bsf.GroovyEngine"/>
<parameter key="rrd-repository" value="/opt/opennms/share/rrd/response" />
</service>
AND
<monitor service="MinGroovy" class-name="org.opennms.netmgt.poller.monitors.BSFMonitor"/>
this is my groovy script:
#!/usr/bin/env groovy\
bsf_monitor.log("ERROR", "Starting MinimalGroovy.groovy", null);
filePath = "//netpath/output/temp.txt"
file = new File(filePath)
if (file.exists()){
return "OK";
}else{
return "NOK";
}
In groovy-starter.conf i added:
enter #lib for opennms
load ${opennms.home}/lib/*.jar
If i run script in groovy console, it works OK!
And this is the error i get in poller.log in OpenNMS:
ERROR [pool-9-thread-27] o.o.n.p.m.BSFMonitor: Starting MinimalGroovy.groovy
Any help?
Your service definition in the poller-configuration.xml looks suspicious to me:
<service name="MinGroovy" interval="300000" user-defined="true" status="on">
<parameter key="file-name" value="C:/OpenNMS/etc/scripts/MinimalGroovy.groovy"/>
<parameter key="bsf-engine" value="org.codehaus.groovy.bsf.GroovyEngine"/>
<parameter key="rrd-repository" value="/opt/opennms/share/rrd/response" />
</service>
The file name is located on "C:/..." whereas your rrd-repository is in "/opt/opennms". Do you have installed OpenNMS on Windows or Linux? The path to your groovy script in the service definition is from the OpenNMS process perspective.

Web Deploy parameterization issue

I'm running into an issue with one of our Sitecore projects. The problem is that certain parameters won't get replaced... I've reproduced the issue in the GitHub repository shown below.
https://github.com/jopmiddelkamp/Web-Deploy-Parameters-issue
With the parameters.xml file below I'm trying to replace mail server values for the Sitecore EXM MAT.
<?xml version="1.0" encoding="utf-8" ?>
<parameters>
<parameter name="Mail Server" description="Mail server to enter into config" tags="Hidden,NoStore" defaultValue="__MailServer__">
<parameterEntry kind="XmlFile" scope="App_Config\\Include\\Sitecore\.Smtp\.config$" match="//sitecore/settings/setting[#name='MailServer']/#value" />
<parameterEntry kind="XmlFile" scope="App_Config\\Include\\EmailExperience\\Sitecore\.EDS\.Providers\.CustomSmtp\.config$" match="//sitecore/exm/eds/smtpSettings/server/text()" />
</parameter>
<parameter name="Mail Server User Name" description="Mail Server User Name to enter into config" tags="Hidden,NoStore" defaultValue="__MailServerUserName__">
<parameterEntry kind="XmlFile" scope="App_Config\\Include\\Sitecore\.Smtp\.config$" match="//sitecore/settings/setting[#name='MailServerUserName']/#value" />
<parameterEntry kind="XmlFile" scope="App_Config\\Include\\EmailExperience\\Sitecore\.EDS\.Providers\.CustomSmtp\.config$" match="//sitecore/exm/eds/smtpSettings/userName/text()" />
</parameter>
<parameter name="Mail Server Password" description="Mail Server Password to enter into config" tags="Hidden,NoStore" defaultValue="__MailServerPassword__">
<parameterEntry kind="XmlFile" scope="App_Config\\Include\\Sitecore\.Smtp\.config$" match="//sitecore/settings/setting[#name='MailServerPassword']/#value" />
<parameterEntry kind="XmlFile" scope="App_Config\\Include\\EmailExperience\\Sitecore\.EDS\.Providers\.CustomSmtp\.config$" match="//sitecore/exm/eds/smtpSettings/password/text()" />
</parameter>
<parameter name="Mail Server Port" description="Mail Server Port to enter into config" tags="Hidden,NoStore" defaultValue="__MailServerPort__">
<parameterEntry kind="XmlFile" scope="App_Config\\Include\\Sitecore\.Smtp\.config$" match="//sitecore/settings/setting[#name='MailServerPort']/#value" />
<parameterEntry kind="XmlFile" scope="App_Config\\Include\\EmailExperience\\Sitecore\.EDS\.Providers\.CustomSmtp\.config$" match="//sitecore/exm/eds/smtpSettings/port/text()" />
</parameter>
<parameter name="EXM Mail Server SSL or TLS Enabled" description="EXM Mail Server SSL/TLS enabled to enter into config" tags="Hidden,NoStore" defaultValue="__MailServerSslOrTlsEnabled__">
<parameterEntry kind="XmlFile" scope="App_Config\\Include\\EmailExperience\\Sitecore\.EDS\.Providers\.CustomSmtp\.config$" match="//sitecore/exm/eds/smtpSettings/startTls/text()" />
</parameter>
<parameter name="EXM Mail Server Authentication Method" description="EXM Mail Server Authentication Method to enter into config" tags="Hidden,NoStore" defaultValue="__MailServerAuthenticationMethod__">
<parameterEntry kind="XmlFile" scope="App_Config\\Include\\EmailExperience\\Sitecore\.EDS\.Providers\.CustomSmtp\.config$" match="//sitecore/exm/eds/smtpSettings/authenticationMethod/text()" />
</parameter>
</parameters>
This generates the SetParameters.xml file as shown below.
<?xml version="1.0" encoding="utf-8"?>
<parameters>
<setParameter name="IIS Web Application Name" value="ParametersTest" />
<setParameter name="Mail Server" value="__MailServer__" />
<setParameter name="Mail Server User Name" value="__MailServerUserName__" />
<setParameter name="Mail Server Password" value="__MailServerPassword__" />
<setParameter name="Mail Server Port" value="__MailServerPort__" />
<setParameter name="EXM Mail Server SSL or TLS Enabled" value="__MailServerSslOrTlsEnabled__" />
<setParameter name="EXM Mail Server Authentication Method" value="__MailServerAuthenticationMethod__" />
</parameters>
So far so good! I want the values to be replaced with the __placeholder__ structure so our VSTS release proces can replace those values with the right environment variables.
Now the problem is that on deployment the userName and password nodes won't get replaced in the \App_Config\Include\EmailExperience\Sitecore.EDS.Providers.CustomSmtp.config file. The result is shown below.
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<exm>
<eds>
...
<smtpSettings type="Sitecore.EDS.Core.Net.Smtp.SmtpSettings, Sitecore.EDS.Core" singleInstance="true">
<server>__MailServer__</server>
<port>__MailServerPort__</port>
<userName></userName>
<password></password>
<authenticationMethod>__MailServerAuthenticationMethod__</authenticationMethod>
<startTls>__MailServerSslOrTlsEnabled__</startTls>
<proxySettings ref="exm/eds/proxySettings" />
</smtpSettings>
...
</eds>
</exm>
</sitecore>
</configuration>
This is weird because the xpath in the match attribute is exactly the same as the Mail Server Port parameter for example... I've also tried to update the parameters.xml file as shown below.
<?xml version="1.0" encoding="utf-8" ?>
<parameters>
<parameter name="Mail Server" description="Mail server to enter into config" tags="Hidden,NoStore" defaultValue="__MailServer__">
<parameterEntry kind="XmlFile" scope="App_Config\\Include\\Sitecore\.Smtp\.config$" match="//sitecore/settings/setting[#name='MailServer']/#value" />
<parameterEntry kind="XmlFile" scope="App_Config\\Include\\EmailExperience\\Sitecore\.EDS\.Providers\.CustomSmtp\.config$" match="//*[local-name()='server']/text()" />
</parameter>
<parameter name="Mail Server User Name" description="Mail Server User Name to enter into config" tags="Hidden,NoStore" defaultValue="__MailServerUserName__">
<parameterEntry kind="XmlFile" scope="App_Config\\Include\\Sitecore\.Smtp\.config$" match="//sitecore/settings/setting[#name='MailServerUserName']/#value" />
<parameterEntry kind="XmlFile" scope="App_Config\\Include\\EmailExperience\\Sitecore\.EDS\.Providers\.CustomSmtp\.config$" match="//*[local-name()='userName']/text()" />
</parameter>
<parameter name="Mail Server Password" description="Mail Server Password to enter into config" tags="Hidden,NoStore" defaultValue="__MailServerPassword__">
<parameterEntry kind="XmlFile" scope="App_Config\\Include\\Sitecore\.Smtp\.config$" match="//sitecore/settings/setting[#name='MailServerPassword']/#value" />
<parameterEntry kind="XmlFile" scope="App_Config\\Include\\EmailExperience\\Sitecore\.EDS\.Providers\.CustomSmtp\.config$" match="//*[local-name()='password']/text()" />
</parameter>
<parameter name="Mail Server Port" description="Mail Server Port to enter into config" tags="Hidden,NoStore" defaultValue="__MailServerPort__">
<parameterEntry kind="XmlFile" scope="App_Config\\Include\\Sitecore\.Smtp\.config$" match="//sitecore/settings/setting[#name='MailServerPort']/#value" />
<parameterEntry kind="XmlFile" scope="App_Config\\Include\\EmailExperience\\Sitecore\.EDS\.Providers\.CustomSmtp\.config$" match="//*[local-name()='port']/text()" />
</parameter>
<parameter name="EXM Mail Server SSL or TLS Enabled" description="EXM Mail Server SSL/TLS enabled to enter into config" tags="Hidden,NoStore" defaultValue="__MailServerSslOrTlsEnabled__">
<parameterEntry kind="XmlFile" scope="App_Config\\Include\\EmailExperience\\Sitecore\.EDS\.Providers\.CustomSmtp\.config$" match="//*[local-name()='startTls']/text()" />
</parameter>
<parameter name="EXM Mail Server Authentication Method" description="EXM Mail Server Authentication Method to enter into config" tags="Hidden,NoStore" defaultValue="__MailServerAuthenticationMethod__">
<parameterEntry kind="XmlFile" scope="App_Config\\Include\\EmailExperience\\Sitecore\.EDS\.Providers\.CustomSmtp\.config$" match="//*[local-name()='authenticationMethod']/text()" />
</parameter>
</parameters>
But this results in the same output... I can't find anything about any reserved names for the userName and password node names...
This is driving me crazy as I can't find a solution. Now I hope anyone here has experinced this issue before and knows how to solve it.
Kind regards,
Jop Middelkamp

Unable to set $(ReplacableToken...) in Web.config when publishing a Web Project

I have a web project and I craeted a Test publish configuration. I use Web Deploy Package for publish method. My target is to have a replacable parameter for a setting in appSettings, so that on deployment a new setting value would be used in SetParameters.xml. I use parameters.xml file created in the root project folder with the following structure.
parameters.config
<parameters>
<parameter name="webApiUrl"
defaultValue="http://localhost:50594/">
<parameterEntry
kind="XmlFile"
scope="Web.config"
match="/configuration/appSettings/add[#key='webApiUrl']/#value" />
</parameter>
</parameters>
Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="webApiUrl" value="http://localhost:50594/" />
</appSettings>
</configuration>
The problem is that when the project is published the webApiUrl setting is not changed to $(ReplacableToken_webApiUrl) so when the project is deployed the value in SetParameters.xml is not taken into consideration.
I used a lot of different variations of scope and match, but non of them worked.
scope="\Web.config$", "obj\x86\Test\Package\PackageTmp\Web.config$", "\Web.config$", "\web.config$"
When I publish the project I check the folder (ProjectRoot)\obj\x86\Test\Package\PackageTmp\Web.config to see if the parametrization works.

MSDeploy setParameter not working

We are trying to integrate a 'build once, deploy anywhere' model in our build-deploy system.
MSDeploy works wonders for this, cutting down build time dramatically with CRC checksum comparisons and (for the most part) it works just as well when using parameterisation to change applications web.configs depending on the environment we deploy to.
I have the majority of these parameters nailed down, but a few elements and attributes never seem to change, no matter how many different ways I call them in the parameters.xml file. I have outlined three examples of this, here is the web.config file I am trying to change:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="DbConnectionString" connectionString="Data Source=null;Initial Catalog=null;Trusted_Connection=no;User ID=user1;Password=pass*9;" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<customErrors mode="On" defaultRedirect="/Library/Error/PageNotFound.aspx">
</customErrors>
</system.web>
<applicationSettings>
<settings>
<setting name="service_Address" serializeAs="String">
<value></value>
</setting>
<settings>
</applicationSettings>
</configuration>
Here is the parameters.xml file:
<parameter name="DbConnectionString" defaultValue="">
<parameterEntry kind="XmlFile" scope="\\web.config$" match="/configuration/connectionStrings/add[#name='DbConnectionString']/#connectionString" />
</parameter>
<parameter name="customErrorsMode" defaultValue="">
<parameterEntry kind="XmlFile" scope="\\web.config$" match="configuration/system.web/customErrors/#mode" />
</parameter>
<parameter name="service_Address" defaultValue="">
<parameterEntry kind="XmlFile" scope="\\web.config$" match="/configuration/applicationSettings/aim.Web.Properties.Settings/setting[#name='service_Address']/value" />
</parameter>
And here is the corresponding setParameters.xml file:
<setParameter name="DbConnectionString" value="Data Source=dbserver;Initial Catalog=DB1;Trusted_Connection=no;User ID=user1;Password=pass*9;"/>
<setParameter name="customErrorsMode" value="Off"/>
<setParameter name="service_Address" value="https://myservice.asmx"/>
I have tested each XPath expression and the results are the exact same as any of the other working parameters, but the above never seem to change.
Does anyone see anything obvious I'm missing here?
service_Address
I found the answer to this problem here:
Replace web.config elements with MSDeploy
I was missing 'text()' at the end of the XPath expression, the correct XPath is:
/configuration/applicationSettings/aim.Web.Properties.Settings/setting[#name='ai‌​m_Web_AddressService_Address']/value/text()
customErrorsMode
For the customErrorsMode problem, I was missing a '/' at the start of my XPath expression. The correct expression is:
/configuration/system.web/customErrors/#mode
connectionStrings
This one really got to me, it was the last one I figured out. After doing a bit of digging I found out that MSDeploy automatically parameterizes certain elements, connection string being one of them, more info here:
Configuring Parameters for Web Package Deployment
My parameter declaration for the connection string in question should have been:
<parameter name="DbConnectionString-Web.config Connection String" defaultValue="">
<parameterEntry kind="XmlFile" scope="\\web.config$" match="/configuration/connectionStrings/add[#name='DbConnectionString']" />
</parameter>
My setParameter definition should have looked like this:
<setParameter name="DbConnectionString-Web.config Connection String" value="Data Source=dbserver;Initial Catalog=DB1;Trusted_Connection=no;User ID=user1;Password=pass*9;" />

getting service from wsdd via xpath not wroking (xmltask)

I am trying to get the XPath "/deployment/service". Tested on this site:
http://www.xmlme.com/XpathTool.aspx
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org /axis/wsdd/providers/java">
<service name="kontowebservice" provider="java:RPC" style="rpc" use="literal">
<parameter name="wsdlTargetNamespace" value="http://strategies.spine"/>
<parameter name="wsdlServiceElement" value="ExposerService"/>
<parameter name="wsdlServicePort" value="kontowebservice"/>
<parameter name="className" value="some.package.internal.KontoWebServiceImpl_WS"/>
<parameter name="wsdlPortType" value="Exposer"/>
<parameter name="typeMappingVersion" value="1.2"/>
<operation xmlns:operNS="http://strategies.spine" xmlns:rtns="http://www.w3.org/2001/XMLSchema" name="expose" qname="operNS:expose" returnQName="exposeReturn" returnType="rtns:anyType" soapAction="">
<parameter xmlns:tns="http://www.w3.org/2001/XMLSchema" qname="in0" type="tns:anyType"/>
</operation>
<parameter name="allowedMethods" value="expose"/>
<parameter name="scope" value="Request"/>
</service>
</deployment>
I absolutely can't find out why it always tells me that my xpath does not match...
This may be stupid, but am I missing something?
EDIT
Thanks to the answer from Dimitre Novatchev I was able to find a workaround:
<xmltask failwithoutmatch="true" report="false">
<fileset dir="${src.gen}/" includes="**/*-deploy.wsdd" />
<copy path="//*[local-name()='service']" buffer="tmpServiceBuf" append="true" />
</xmltask>
<xmltask failwithoutmatch="true" report="false" source="${basedir}/env/axis/WEB-INF/server-config.wsdd" dest="${build.stage}/resources/WEB-INF/server-config.wsdd">
<insert path="//*[local-name()='transport'][last()]" buffer="tmpServiceBuf" position="after" />
</xmltask>
Binding namespaces with xmltask (which is the tool that gave me the headaches) seems not to be possible. The code above did the trick.
The Problem: This XML document has a default namespace. XPath considers any unprefixed names to be in "no-namespace". It tries to select /deployment/service where the elements deployment and service are in no-namespace and doesn't select any node, because in the provided XML documents there are no such elements that are in "no- namespace (they all are in the "http://xml.apache.org/axis/wsdd/" namespace)
The solution: Using the language which hosts XPath (such as C#, Jave, XSLT, or any other language that you may be using) bind a prefix (say x:) to the namespace "http://xml.apache.org/axis/wsdd/".
Then, change:
/deployment/service
to
/x:deployment/x:service
Now the last XPath expression correctly selects the desired node.

Resources