Can I actually deploy F# console app as Azure WebJob? Can't find a proper option in VS2017 :(
And if it's possible, can you have a look at my code? Would it work as it is if I will deploy it as AzureWebJob? Do I need to change something?
open FSharp.Data;
open System
open System.Net.Mail
let server = "smtp.gmail.com"
let sender = "fsharpie.send#gmail.com"
let password = "password"
let port = 587
let SendTest email topic msg =
use msg =
new MailMessage(
sender, email, topic,
msg)
let client = new SmtpClient(server, port)
client.EnableSsl <- true
client.Timeout <- 20000
client.DeliveryMethod <- SmtpDeliveryMethod.Network
client.UseDefaultCredentials <- false
client.Credentials <- System.Net.NetworkCredential(sender, password)
client.Send msg
let metaTitle (doc:HtmlDocument) =
doc.Descendants "meta"
|> Seq.choose (fun x ->
match x.AttributeValue("name"), x.AttributeValue("property") with
| "title", _
| "headline", _
| "twitter:title", _
| _, "og:title" ->
Some(x.AttributeValue("content"))
| _, _ -> None
)
let titles (doc:HtmlDocument) =
let tagged (tag:string) =
doc.Descendants tag |> Seq.map (fun x -> x.InnerText())
Seq.concat [tagged "title"; metaTitle doc; tagged "h1"]
let title (doc:HtmlDocument) =
titles doc |> Seq.tryHead
let finalTitle (link:string) = try
link
|> HtmlDocument.Load
|> titles
|> Seq.head
with
| :? Exception as ex -> ex.Message
[<EntryPoint>]
let main argv =
let website = "website.com"
if(finalTitle website <> "expected title")
then
SendTest "result#gmail.com" "Status: Failed" (website + " is down :( ")
0 // return an integer exit code
Can I actually deploy F# console app as Azure WebJob?
Yes, we can delploy F# console app as Azure WebJob
Can't find a proper option in VS2017
Publish F# project as Azure webjob from VS2017 tool directly is not supported currently.
But we can publish the F# project from Azure Portal.I did a demo for it. The following is my detail steps:
1.Create F# project with VS2017
2.Install the WebJob SKD in the project
3.Build the project and Zip the release or debug file in the bin folder
4.Upload the Zip file from Azure portal
5.Config the Appsetting with Storage connection string
6.Check the webjob with Azure Kudu(https://yourwebsite.scm.azurewebsites.net) tool
You need to create an .exe from your f# code, create a zip from the output folder and upload it to Azure.
https://blogs.msdn.microsoft.com/dave_crooks_dev_blog/2015/02/18/deploying-f-web-job-to-azure/
Another option is use Azure Functions which is the evolution of Azure WebJobs and has support for f#: https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-fsharp
Related
All,
I am trying to automate infrastructure where I am using Azure DevOps CI / CD Pipeline for deploying VM and using DSC to configure / install SCOM using Module XSCOM 1.3.3.0. As per my colleague, the below code works on a VMWare VM.
Question:
Any idea on the below error or any other method of installing SCOM on an Azure machine in an automated fashion?
DSC Code:
xSCOMManagementServerSetup "OMMS"
{
DependsOn = #('[Package]ODBCDriver13', '[Package]SQLClient11')
Ensure = "Present"
SourcePath = $SCM2016Path
SetupCredential = $AdminCreds
#ProductKey = $Node.SCM2016Key
ManagementGroupName = $MgmtGrp
InstallPath = $SCM2016InstallPath
FirstManagementServer = $false
ActionAccount = $OpsActionCredential
DASAccount = $OpsSDKCredential
DataReader = $OpsDRACredential
DataWriter = $OpsDWACredential
SqlServerInstance = $SCM2016DB
DatabaseSize = $DatabaseSize
DwSqlServerInstance = $SCM2016DWDB
DWDatabaseSize = $DWDatabaseSize
# UseMicrosoftUpdate =
}
xSCOMWebConsoleServerSetup "OMWC"
{
DependsOn = '[xSCOMManagementServerSetup]OMMS'
Ensure = "Present"
SourcePath = $SCM2016Path
SetupCredential = $AdminCreds
InstallPath = $SCM2016InstallPath
ManagementServer = $nodename
WebSiteName = "Default Web Site"
WebConsoleAuthorizationMode = "Mixed"
WebConsoleUseSSL = $false
}
xSCOMConsoleSetup "OMC"
{
DependsOn = '[xSCOMWebConsoleServerSetup]OMWC'
Ensure = "Present"
SourcePath = $SCM2016Path
InstallPath = $SCM2016InstallPath
SetupCredential = $AdminCreds
}
Error:
Job {94883009-5CFE-11EC-A811-002248041883} :
Message Set-TargetResouce failed
HResult -2146233087
StackTrack at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
at Microsoft.PowerShell.DesiredStateConfiguration.Internal.ResourceProviderAdapter.ExecuteCommand(PowerShell powerShell, ResourceModuleInfo resInfo, String operationCmd, List`1 acceptedProperties, CimInstance nonResourcePropeties, CimInstance resourceConfiguration, LCMDebugMode debugMode, PSInvocationSettings pSInvocationSettings, UInt32& resultStatusHandle, Collection`1& result, ErrorRecord& errorRecord, PSModuleInfo localRunSpaceModuleInfo)
All System Center Operations Manager (SCOM) individual management group deployments will either be an "all-in-one" installation, where all features are loaded on a single server, or a distributed installation. Deploying System Center Operations Manager describes more about the same.
The Install-SCOMAgent cmdlet deploys one or more System Center 2019 - Operations Manager and later product version agents by using client push installation. The code snippet below shows the syntax.
Install-SCOMAgent
[-ActionAccount <PSCredential>]
[-AgentActionAccount <PSCredential>]
-DNSHostName <String[]>
-PrimaryManagementServer <ManagementServer>
[-NoAPM]
[-PassThru]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Check Install-SCOMAgent document for examples. Also check Setup and configure Log Analytics using SCOM.
But as far as I know there is no way of installing the SCOM management server role without first uninstalling the Log Analytics/Azure Monitoring agent. You should be able to connect your server by using the SCOM agent to connect to the Log Analytics Workspace afterwards, check Connect Operations Manager to Azure Monitor for more information.
Also check this Automate SCOM 2016 installation with PowerShell to automate the installation of SCOM on azure virtual machine (Windows Server 2016).
How can I get teamcity build plan's VCS root url on python? I've looked upon teamcity rest api documentation and googled if someone already had that problem - but seems there is no similar problems out in the internet.
from dohq_teamcity import TeamCity
from dohq_teamcity.configuration import Configuration
from settings.config import settings
config = Configuration()
config.api_key = {'token': settings.TEAMCITY_TOKEN}
config.api_key_prefix = {'token': 'Bearer'}
config.active_api_key = 'token'
tc = TeamCity(settings.TEAMCITY_URL, auth_settings=["Token"], configuration=config)
vcs_roots_locators = [x.locator_id for x in tc.vcs_root.get_roots().data]
def get_vcs_roots_vcs_url(tc: TeamCity, locator: str) -> str:
vcs_root = tc.vcs_root.get_root(vcs_root_locator=locator)
return [y for y in vcs_root.properties.data if y.name == 'url'][0].value
vcs_roots_urls = [get_vcs_roots_vcs_url(tc, x) for x in vcs_roots_locators]
print(vcs_roots_urls)
I am been trying to download an sln from Azure DevOps but I get this message that wants me to remap the local path. The current mapped local is correct where I want it on my desktop but this pop-up comes up and then I can't open the project file.
GlobalSection(TeamFoundationVersionControl) = preSolution
SccNumberOfProjects = 3
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
SccTeamFoundationServer = https://nccn.visualstudio.com/defaultcollection
SccProjectUniqueName0 = ..\\NCCN\u0020Libraries\\GuidelineDataLayer\\GuidelineDataLayer\\GuidelineDataLayer.csproj
SccProjectName0 = ../../NCCN\u0020Libraries/GuidelineDataLayer/GuidelineDataLayer
SccLocalPath0 = ..\\NCCN\u0020Libraries\\GuidelineDataLayer\\GuidelineDataLayer
SccLocalPath1 = .
SccProjectUniqueName2 = NccnWebApi\\Nccn.WebService.GAT.csproj
SccProjectName2 = NccnWebApi
SccLocalPath2 = NccnWebApi
EndGlobalSection
I am trying to set up a very simple test F# project in linux with mono, using Forge to set up the project and install nuget packages. Forge creates a build.fsx file which uses FAKE. I've tried to adjust this build file (in order to add tests) with inspiration from this tutorial http://fsharp.github.io/FAKE/gettingstarted.html. The tutorial, however, is using C# for testing and assumes Windows with .Net as environment. I want to use F# for testing and linux with mono as environment.
I think I almost got it working, but I am getting some cryptic error messages from NUnit. When running the build.fsx file I get following errors at the end:
...
Invalid argument: -nologo
The value '/home/michel/Documents/FSHARP/UnitTests/test/NUnit.Test.MyTests.dll' is not valid for option '--labels'.
Invalid argument: -xml:./test/TestResults.xml
Running build failed.
Error:
NUnit test failed (255).
---------------------------------------------------------------------
Build Time Report
---------------------------------------------------------------------
Target Duration
------ --------
Clean 00:00:00.0036366
Build 00:00:00.0402828
BuildTest 00:00:00.4911710
Total: 00:00:00.7494956
Status: Failure
---------------------------------------------------------------------
1) Fake.UnitTestCommon+FailedTestsException: NUnit test failed (255).
at Fake.NUnitSequential.NUnit (Microsoft.FSharp.Core.FSharpFunc`2 setParams, IEnumerable`1 assemblies) <0x41d27e50 + 0x0039f> in <filename unknown>:0
at FSI_0001+clo#32-4.Invoke (Microsoft.FSharp.Core.Unit _arg4) <0x41d27dc0 + 0x0006f> in <filename unknown>:0
at Fake.TargetHelper+targetFromTemplate#195[a].Invoke (Microsoft.FSharp.Core.Unit unitVar0) <0x41cd59b0 + 0x00023> in <filename unknown>:0
at Fake.TargetHelper.runSingleTarget (Fake.TargetTemplate`1 target) <0x41ccb490 + 0x000ca> in <filename unknown>:0
My build.fsx file looks like this
// include Fake libs
#r "./packages/FAKE/tools/FakeLib.dll"
open Fake
// Directories
let buildDir = "./build/"
let testDir = "./test/"
// version info
let version = "0.1" // or retrieve from CI server
// Targets
Target "Clean" (fun _ ->
CleanDirs [buildDir; testDir]
)
Target "Build" (fun _ ->
//MSBuildDebug buildDir "Build" appReferences
!! "/UnitTesting/*.fsproj"
|> MSBuildRelease buildDir "Build"
|> Log "AppBuild-Output: "
)
Target "BuildTest" (fun _ ->
!! "src/NUnit.Test.MyTests/*.fsproj"
|> MSBuildDebug testDir "Build"
|> Log "TestBuild-Output: "
)
Target "Test" (fun _ ->
!! (testDir + "/NUnit.Test.MyTests.dll")
|> NUnit (fun p ->
{ p with
ToolPath = "packages/NUnit.ConsoleRunner/tools"
//DisableShadowCopy = true;
OutputFile = testDir + "TestResults.xml" })
)
Target "Default" (fun _ -> trace "HEEEELLOOOOOO world from FAKE!!!")
"Clean" ==> "Build" ==> "BuildTest" ==> "Test" ==> "Default"
RunTargetOrDefault "Default"
FAKE seems to be looking for a file nunit-console.exe under the packages/NUnit.ConsoleRunner/tools directory, but there is no such file. However, there is a nunit3-console.exe file, so I just made a copy of this file with the name nunit-console.exe.
My simple test file NUnit.Test.MyTests.fs looks like following:
namespace NUnit.Test.MyTests
module testmodule =
open NUnit.Framework
let SayHello name = "Hello"
[<TestFixture>]
type myFixture() =
[<Test>]
member self.myTest() =
Assert.AreEqual("Hello World!", SayHello "World")
and the file test/NUnit.Test.MyTests.dll seems to be generated just fine.
What does the cryptic error message mean, and how can I fix it so I can run my tests?
As mentioned by rmunn in the comment, I need to use the function NUnit3 because I am using NUnit version 3.4.1. The function resides in the FAKE.Testing module http://fsharp.github.io/FAKE/apidocs/fake-testing-nunit3.html. I modified my build.fsx file so it now looks like following:
// include Fake libs
#r "./packages/FAKE/tools/FakeLib.dll"
open Fake
open Fake.Testing // NUnit3 is in here
// Directories
let buildDir = "./build/"
let testDir = "./test/"
// version info
let version = "0.1" // or retrieve from CI server
// Targets
Target "Clean" (fun _ ->
CleanDirs [buildDir; testDir]
)
Target "Build" (fun _ ->
!! "/UnitTesting/*.fsproj"
|> MSBuildRelease buildDir "Build"
|> Log "AppBuild-Output: "
)
Target "BuildTest" (fun _ ->
!! "src/NUnit.Test.MyTests/*.fsproj"
|> MSBuildDebug testDir "Build"
|> Log "TestBuild-Output: "
)
Target "Test" (fun _ ->
!! (testDir + "/NUnit.Test.*.dll")
|> NUnit3 (fun p ->
{ p with
ToolPath = "packages/NUnit.ConsoleRunner/tools/nunit3-console.exe" })
)
Target "Default" (fun _ -> trace "HEEEELLOOOOOO world from FAKE!!!")
"Clean" ==> "Build" ==> "BuildTest" ==> "Test" ==> "Default"
RunTargetOrDefault "Default"
Note that you must specify ToolPath all the way to the nunit3-console.exe file, and not just the directory where it resides.
Now everything seems to work, and I get a fine and simple 'test-summary' in the console output when I run build.fsx. :)
I'm trying to make an application that scrapes news headlines from the BBC News site, send a notification out to the users desktop when the files have been retrieved and then gives the user the option to open a window showing the titles of articles and their links. Everything is fine except the last part - I can't get fdo-notify to run an action. I'm not really sure what the syntax would be but this is what I have:
broadCastHeadlines = do
client <- connectSession
let startNote = Note { appName = "BBC News Headlines" , appImage = Nothing ,
summary="BBC News Headlines", actions = [], hints = [],
body=(Just $ Text "Latest Headlines"),
expiry = Never}
notification <- notify client startNote
headlines <- readHeadlinesFromFile
--let headlines' = unlines $ map show headlines
let endNote = Note { appName = "BBC News Headlines" , appImage = Nothing ,
summary="BBC News Headlines", actions = [(Action {actionName = "UI.main"}, "Open")], hints = [],
body=(Just $ Text ((getTitle $ head headlines) ++ " and " ++ (show $ length headlines) ++ " more stories.")), expiry = Never}
headlines `seq` replace client notification endNote
How do I get the Action to run UI.main?
Update
This is the link to the library repository: http://bitbucket.org/taejo/fdo-notify/