Validate Kusto query before submitting it - azure-data-explorer

Is there a way (in Powershell would be best, but also otherwise) to check for KQL syntax before submitting it to a cluster?
I want to check sanity of a KQL code repo in my CI pipeline.
Thank you!

Yes, you can use the Kusto Query Language parser (.Net library) for this, start from the samples doc.

Step 1 : Install :
Install-PackageProvider -Name NuGet -Scope CurrentUser
Register-PackageSource -Name nuget.org -ProviderName NuGet -Location https://www.nuget.org/api/v2
Install-Package -Name Microsoft.Azure.Kusto.Language -ProviderName NuGet -scope CurrentUser
Step 2 : Run query :
$kql="T | project a = a + b | where a > 10.0"
$nuGetPath=Get-Package -Name "Microsoft.Azure.Kusto.Language" | Select-Object -ExpandProperty Source
$dllPath=(Split-Path -Path $nuGetPath) + "\lib\netstandard2.0\Kusto.Language.dll"
[System.Reflection.Assembly]::LoadFrom($dllPath)
$kustoParse=[Kusto.Language.KustoCode]::Parse($kql)
$kustoParse.getDiagnostics()

Related

Getting build error while building docker image for asp.net app

I created a simple ASP.NET Web API (4.5.2 framework) application.
This is a simple project I created using file > New > Project > Web > Asp.net web application and selecting ASP.NET Web Api option.
I am trying to create a Docker image getting following error.
Here is my script
#escape=`
# get the build agent image to build the project
FROM sixeyed/msbuild:netfx-4.5.2-webdeploy As build-agent
WORKDIR C:\Users\jason\source\repos\FirstApp\FirstApp
COPY FirstApp\packages.config .
RUN nuget restore packages.config -PackagesDirectory ..\packages
COPY FirstApp\ C:\Users\jason\source\repos\FirstApp\FirstApp
RUN msbuild FirstApp.csproj /p:OutputPath=c:\out /p:DeployOnBuild=true `
/p:VSToolsPath=C:\MSBuild.Microsoft.VisualStuio.Web.targets.14.0.0.3\tools\VSToolsPath
#docker image build --tag firstapp --file .\Dockerfile .
# now build the app
FROM microsoft/aspnet:windowsservercore
SHELL ["powershell"]
WORKDIR c:\web-app
RUN Remove-Website -Name 'Default Web Site'; `
New-Website -Name 'web-app' -Port 80 -PhysicalPath 'C:\web-app'
copy --from=build-agent c:\out\_PublishedWebsites\FirstApp c:\web-app
I am getting following error:
Step 10/11 : RUN Remove-Website -Name 'Default Web Site'; New-Website -Name 'web-app' -Port 80 -PhysicalPath 'C:\web-app'
---> Using cache
---> e37d8f12a4f7
Step 11/11 : copy --from=build-agent c:\out\_PublishedWebsites\FirstApp c:\web-app
docker : COPY failed: CreateFile \\?\Volume{ffe73e3d-cc0b-11e8-a943-00155d1c3a78}\out\_PublishedWebsites\FirstApp: The system cannot find the path specified.
At line:1 char:1
+ docker image build --tag firstapp --file .\Dockerfile .
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (COPY failed: Cr...path specified.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
I looked and found, there is no c:\out folder. I do not see this folder after executing this command as well:
RUN msbuild FirstApp.csproj /p:OutputPath=c:\out /p:DeployOnBuild=true `
/p:VSToolsPath=C:\MSBuild.Microsoft.VisualStuio.Web.targets.14.0.0.3\tools\VSToolsPath
Seems like a simple issue but I am not sure where can I see logs and how to fix this issue.

How to publish a .Net Core lambda function using TeamCity

I work on a .Net Core solution in which we just added .Net Core lambdas.
The newly created lambdas are all set, including the aws-lambda-tools.json.
All I have left to do is to automatically publish those lambdas using TeamCity.
(Continuous deployment is already set on TC for the rest of the solution)
Also I'd rather not update a TC build step every time we add a new Lambda.
How can I setup TC to automatically publish all lambdas?
Shall I use the .Net CLI or are there any plugin to help me configure this step?
Finally, I opted for a very simple powershell script at the root of the solution, that deploys all the projects whose aws-lambda-tools-defaults are set:
$lambdaProfile = "aws-lambda-tools-defaults.json"
$solutionFolder = (Get-Item -Path ".\" -Verbose).FullName;
$lambdaFolders = Get-ChildItem -Path $solutionFolder -File -Recurse aws-lambda-tools-defaults*.json | ForEach-Object {$_.DirectoryName } | Select-Object -uniq
forEach ($lambdaFolder in $lambdaFolders)
{
Write-Output "Deploying following lambda: $lambdaFolder"
Write-Output "with profile: $lambdaProfile"
Set-Location $lambdaFolder
dotnet lambda deploy-function -cfg $lambdaProfile
Set-Location $solutionFolder
}
Then just execute this script in a specific build step on TeamCity,

Cannot commit configuration changes because the file has changed on disk

I would like to have a powershell script that could create an IIS web site.
but I am getting error
New-IISSite : Filename:
\?\C:\Windows\system32\inetsrv\config\applicationHost.config Error:
Cannot commit configuration changes because the file has changed on
disk At C:\projects\salonsecretSrc\RegisterWebSite.ps1:38 char:9
+ New-IISSite -BindingInformation $strIssBindigFormat -Name $st ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-IISSite], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.IIS.Powershell.Commands.NewIISSiteComman
this is my script:
$strCurrentPath = $MyInvocation.MyCommand.Path
$strWebSiteFolder = Get-ChildItem (dir $strCurrentPath)
$strWebSiteBindingPath = $strWebSiteFolder.Directory.FullName+"\build\WebSite"
$strCurrentFolderName = $strWebSiteFolder.Directory.Name
$strIssSiteName = "$strCurrentFolderName.local"
$strIssBindigFormat = ":80:$strIssSiteName"
Write-Host "Current Script path: $strCurrentPath"
Write-Host "IIS Web Site phycical path: $strWebSiteBindingPath"
Write-Host "IIS SiteName: $strIssSiteName"
Write-Host "IIS Bindindg Format: $strIssBindigFormat"
Write-Host "Creating App Pool - $strIssSiteName"
New-WebAppPool -Name $strIssSiteName -Force
Write-Host "Creating Web Site Pool - $strIssSiteName"
New-IISSite -BindingInformation $strIssBindigFormat -Name $strIssSiteName -PhysicalPath "$strWebSiteBindingPath" -Force
Write-Host "Mapping Pull and Web Site - $strIssSiteName"
Set-ItemProperty "IIS:\Sites\$strIssSiteName" -name applicationPool -value $strIssSiteName
Write-Host "$strIssSiteName WebSite Created"
what could be an issue how to solve ?
it could create an web site first time but second time if I remove it manually it will get this error.
There are many different things that can lock the applicationHost.config file and cause powershell commands like New-IISSite to fail.
In this case, you mentioned you deleted the site manually so perhaps you still have IIS Manager open and it is locking the file. I suggest closing IIS Manager.
As described in this blog post on Powershell and IIS, the makers of Octopus Deploy have found that the only reliable solution to the file-locking problem is to wrap any file-altering commands like New-WebAppPool in try-catch blocks and retry these operations multiple times. The source code for a function to do this is found in the blog.
It seems something really screwy is going on with New-IISSite command. I ended up dropping back to New-Website (via WebAdmistration module), and all the problems went away.
Since this is the first entry in google about this issue, I will describe my findings to the cause of the error message here. It's maybe not related to OPs issue.
Example for failing code
Get-IISAppPool
New-WebAppPool -Name TestAppPool
New-IISSite -Name TestSite -PhysicalPath D:\ -BindingInformation *:80:test
Explaination
If using Get-IISAppPool from the IISAdministration PowerShell Module
followed by New-WebAppPool from the WebAdministration PowerShell Module,
the command Get-IISAppPool will somehow prevent New-WebAppPool from closing the applicationHost.config file and probably leaves it in an open state.
If we now run New-IISSite, we will get the Error:
New-IISSite : Filename: \\?\C:\Windows\system32\inetsrv\config\applicationHost.config Error: Cannot commit configuration changes because the file has changed on disk
I was able to reproduce this with other Commands too if followed the order described above:
Get-*Cmdlet from IISAdministration Module
New-*Cmdlet from WebAdministration Module
New-IISSiteBinding from IISAdministration Module
Prevention of the issue
To workaround this issue I found two solutions.
Remove the IISAdministration Module before executing New-IISSite
Wrap Get-IISAppPool and New-WebAppPool in Start-IISCommitDelay / Stop-IISCommitDelay
Only use one of the Modules. I decided to only use the IISAdministration Module. It's not in the Microsoft Docs but you can create/delete AppPools with it too using the Get-IISServerManager cmdlet as described here.
Workaround 1
Get-IISAppPool
New-WebAppPool -Name TestAppPool
Remove-Module IISAdministration
New-IISSite -Name TestSite -PhysicalPath D:\ -BindingInformation *:80:test
Workaround 2
Start-IISCommitDelay
Get-IISAppPool
New-WebAppPool -Name TestAppPool
Stop-IISCommitDelay
New-IISSite -Name TestSite -PhysicalPath D:\ -BindingInformation *:80:test

Powershell Get-WebSite name parameter is ignored

I want to retrieve information regarding specific IIS 7 website using the PowerShell Get-Website cmdlet. Unfortunately, Get-Website returns information for all websites regardless of the -Name parameter I pass in. It appears that the -Name parameter is ignored.
For instance, if I use:
Import-Module WebAdministration
Get-Website -Name "Test Website"
I will receive information for all websites on my machine:
Name ID State Physical Path Bindings
---- -- ----- ------------- --------
Default Web Site 1 Started %SystemDrive%\inetpub\wwwroot http *:80:
net.tcp 808:*
net.pipe *
net.msmq localhost
msmq.formatname localhost
Test Website 2 Started C:\websites\test http *:80:test.mydomain.com
According to the documentation Get-Website should return information for the website specified in the -Name parameter. I must be misunderstanding the documentation or misusing the cmdlet, or both.
How should I use Get-Website to return information for a specific website?
According to this forum post, this is a bug in the Get-Website cmdlet. The workaround until this is addressed is to use Get-Item.
$website = "Test"
Get-Item "IIS:\sites\$website"
Be sure to use double quotes, variables are not expanded when single quotes are used.
I realize it's an older post but I ran into this issue recently and found your question. I've had luck with the following syntax too:
get-website | where { $_.Name -eq 'foobar' }
Using wild cards will also get around this issue as mentioned in the work around in the connect topic referenced by #Joey
get-website -name "*Default Web Site*"

SVN Reporting in ASP.Net

We have a custom project management tool built in ASP,net 3.5 and we use VisualSVN for our version management. However, we are looking a way to report the version changes through the project management tool by integrating VisualSVN with our project management tool, i.e. pretty much similar to what Trac [python based SCM tool] provides.
Basically looking for a simple VisualSVN Client API to be able to detect & report the file changes based on the revision set provided.
There is also SharpSvn wich encapsulates the whole Subversion 1.5 client api. It's is licensed under the Apache 2.0 license and it's from CollabNet.
Check Svn.NET I think is the best solution for right now .NET bindings of the Subversion client system libraries.
If you're happy with some scripting, you can use svnlook, which is the tool that provides reports on changes and repository modifications.
I use it in a post-commit hook to send the changes of all files to my bugtracker, so it can display which files were changed given a revision number. I add a specific text to the log, and it picks that up to know which bug to associate the data with.
EDIT, as requested, this perl script is called from the post-commit hook:
$url = `svnlook log -r $ARGV[1] $ARGV[0]`;
# check the string contains the matching regexp,
# quit if it doesn't so we don't waste time contacting the webserver
# this is the g_source_control_regexp value in mantis.
exit 1 if not $url =~ /\b(?:bug|issue|mantis)\s*[#]{0,1}(\d+)\b/i;
$url = $url . "---\nSVN Revision: " . $ARGV[1];
$url = $url . "\n" . `svnlook dirs-changed -r $ARGV[1] $ARGV[0]`;
#urlencode the string
$url =~ s/([^\w\-\.\#])/$1 eq " "?"+": sprintf("%%%2.2x",ord($1))/eg;
print "log=$url";
exit 0;
this writes to the postcommit_mantis.txt file which is sent to Mantis via curl:
d:\tools\curl -s -d user=svn -d #c:\temp\postcommit_mantis.txt http://<server>/mantis/core/checkincurl.php

Resources