Powershell with Dataloop/Outlyer - powershell

I'm not sure if this is the correct page for this question but I'm having a hard time getting Dataloop to properly display a widget based on my Powershell script's exit code.
I've just began playing with Dataloop monitoring so I may be going about this all wrong, but as far as I can tell from their documentation, they use the same error code system as Nagios and that those error codes map to a .status metric within Dataloop which you can use for displaying widgets.
As a test, I created the following Powershell script:
if (Test-path c:\scripts02) {
Write-Host "I found the directory!"
exit 0
}
else {
Write-Host "I could not find the directory!"
exit 2
}
When I run the plugin test through the Dataloop site, this prints out the "I could not find the directory!" message along with the correct exit code of 2. When I change the path it's testing to an existing directory, it does exit with 0 and the correct output message. Everything seems to work as expected before until I move to the next part.
Inside Dataloop, I'd attempt to add a widget, set the source to one of my agents, select the "status" metric for my test plugin (the powershell script). The widget just appears with a gray screen when it should be green since the directory path does exist...
Has anyone had success with this? I checked out their documentation and tried the steps outlined there but have had no success.

For anyone who's interested, this is actually a bug in the dataloop agent v1.1. Updated to v1.3 and code executes properly and reports the correct exit code.
On a side note, I had to use the function below to get dataloop to report properly as well instead of the "exit [int]" in my original code above:
function ExitWithCode {
param($exitcode)
$host.SetShouldExit($exitcode)
exit
}

Related

Can I write custom task start/end records to VSTS build/release log

I would like to be able to add items to the logs displayed during VSTS builds and releases:
I've looked at this page and written the following test powershell script
$guid = $env:taskGuid
write-host "##vso[task.logdetail id=$guid;name=project1;type=build;order=1]create new timeline record"
# write-host "##vso[task.logdetail id=new guid;parentid=exist timeline record guid;name=project1;type=build;order=1]create new nested timeline record"
write-host "##vso[task.logdetail id=$guid;progress=50;state=InProgress;]update timeline record"
write-host "##vso[task.logdetail id=$guid;state=Completed;result=Succeeded]complete timeline record"
I was hoping to see additional entries in the log but I see no difference at all, not even the write-host statements appearing.
So I have 2 questions
What should I see from my sample script above?
Is it possible to get
additional entries in that log shown in the initial screenshot
without actually adding additional tasks?
The syntax you're using is designed to show in the timeline which doesn't appear to be used in the new build layout yet (see here to disable preview of new build output). If you use the old build output, select the step for the powershell script you're executing and then select time line, you will then see your step (which in my case is ssloan) being logged by the logger. . See here for a better run down of the various build steps than I could give.
For just outputting the the logs you can use a variety of writers provided in PowerShell utilities Write-Host should be sufficient so long as you always have a host to write to. These will then appear in your logs

Working with layout object attributes and variables in FileMaker

This is the first time I'm encountering GetLayoutObjectAttribute and I am having serious issues with it. My variable $web won't set. I think it's because PD_WebV isn't the right object name to refer to, but I don't know how to find the right object name. I can't find the objects name when I hit Edit Layout, so does anyone know how to find an layout objects name?
Loop
Pause/Resume Script [Duration (seconds): 1]
Set Variable[$Web; Value: GetLayoutObjectAttribute("PD_WebV";"content")]
If[$Web="done"]
#execute if statements
After Edit:
After some troubleshooting, I found out that PD_WebV is the right object name to refer and it's refered to correctly, so my new question is why doesn't the script go to the line If[$Web="done"] and how could I fix it? Ss my If statement not evaluating something it should be? Is my $web variable never set to done or is the issue something completely different? Would the problem possibly have to do with my WebDirect sharing settings? Any guidance would help. Thanks.
After, After Edit:
So now that my application is getting past Set Variable[$Web; Value: GetLayoutObjectAttribute("PD_WebV";"content")], the variable $web only equals <HTML></HTML>. Does anyone know a way, without using javascript, to test the inside of the html tags?
Also, I printed the bounds of the webViewer PD_WebV that I can't locate on the layout but am referring to in the script. The bounds that are printed are different each time I run the script. Is the usual or unusual? My source is also about:blank so it doesn't look like I'm sourcing from a URL
Is my $web variable never set to done or is the issue something
completely different?
If you're doing:
Set Variable[$Web; Value: GetLayoutObjectAttribute("PD_WebV";"content")]
then the only time
$Web="done"
will return true is when the web page loaded into your web viewer contains exactly the string "done" (in practical terms, that's never).
I have already suggested in a comment that you test for:
PatternCount ( $webpage ; "</html>" )
This is assuming you want the subsequent steps to execute only after the page has finished loading. The entire script would look something like this:
Loop
Pause/Resume Script [Duration (seconds): 1]
Set Variable[$Web; Value: GetLayoutObjectAttribute("PD_WebV";"content")]
Exit Loop If [ PatternCount ( $webpage ; "</html>" ) ]
End Loop
# execute statements
You might also want to add a counter to the loop and exit the script after n trials.
Ah, I reread your question.
To set the object name for your webviewer so that the GetLayoutObjectAttribute function works you need to set it in the Name field in the inspector when you have the webviewer selected.
e.g.:
After that your variable should populate.
Be aware
What it will populate with will be all of the html from the browser, i.e. not a boolean true/false liek your conditional suggests.
I'm not sure exactly what you're trying to accomplish, but to be able to determine a result from your web viewer you'll need to either parse the HTML to see if it's content contains what you're looking for or within the code you're setting the webviewer with, fire a javascript function that calls back to the FileMaker file using a FileMaker url.

TeamCity checkbox parameter

I am looking to implement a flag to make sure no one tiggers a job by mistake.
I have added a parameter which prompts before the the job is triggerd.
An command line build step is created with the following script:
IF %ConfirmationCheck% == "false" exit 1;
No matter what setting the confirmation box has, it always starts the rest of the steps.
Anyone an idea?
Thx
I'm using powershell to do the same thing
if ("%ConfirmPrompt%" -eq "false")
{
Write-Host "Error: Confirmation checkbox was not checked"
exit 1
}
Make sure that you edit the parameter and set the un/checked value, mine are set to false/true respectively.

Teamcity SetParameter doesn't seem to be working

As the first step in a build configuration I am trying to dynamically change a parameter and use it in the subsequent steps. Reading online, it seems that the way to do this is to call ##teamcity[setParameter. But this doesn't seem to be working. It doesn't even change the value in the same step.
For example, I have created a test parameter and set it's default value to '1'. Inside a powershell script, I tried to change it to 2, as shown below.
But the output remains unchanged as can be seen below
I am currently using TeamCity 8.0.3 (build 27540). What am I doing wrong?
EDIT: I think the problem might be the command you're using to set the parameter. Try:
Write-Host "##teamcity[setParameter name='TestParameter' value='2']"
--
We've experienced the same behavior. The key here is 'subsequent steps.' You must modify the parameter in a separate build step that is run before the step in which you want to use the new parameter.
It's my understanding that all parameters in a build step are evaluated immediately before the execution of that step. The tokens will be replaced with the unmodified values of those parameters. Thus, what actually gets executed by the build agent is:
Write-Host "TestParameter value is 1"
Write-Host "##teamcity[setParameter name='TestParameter' value='2']"
Write-Host "TestParameter value is 1"

Error when re-declaring item as record via PowerShell - "The file has been modified "SHAREPOINT\system"

We have had a PowerShell script scheduled and executing successfully for the past 3-4 months (In both Test and Prod). The purpose of the script is to update document properties in SharePoint when certain triggers are fired from external systems. Without getting into too much detail, below is the code that has been used to update item properties for a document that has been declared a record:
$recordsmanagement=[Microsoft.Office.RecordsManagement.RecordsRepository.Records]
$recordsmanagement::UndeclareItemAsRecord($item)
$item = $list.GetItemById($item.id)
$item.File.CheckOut()
$item[$sSpFieldName]=$sDbValue
$item.Update()
$item = $list.GetItemById($item.id)
$item.File.CheckIn("")
$recordsmanagement::DeclareItemAsRecord($item)
This code has worked hundreds of times without a problem. For some reason, this code started bombing a week ago on the last line (when re-declaring as a record):
System.Management.Automation.MethodInvocationException: Exception calling "DeclareItemAsRecord" with "1" argument(s): "The file /lib/folder/file.pdf has been modified by SHAREPOINT\system on 10 Oct 2012 00:00:47 -0500."
The other weird part is that this is only happening in Prod. The Test environment seems to execute just fine. I haven't tried a fix for production yet, but I'm pretty sure I can just get the $item object again using GetItemById (after the CheckIn). I'm a little hesitant to do this just yet as I wanted to get some other people's perspective first.
Does anyone have any input on this? Thanks in advance.
I think the best bet is to get the item again after the checkin as you say.
The error message indicates exactly that. You are trying to perform an operation on a SPListItem that has been modified. So pull it again using GetItemById before you declare it as a record.
Why it only happens on some records and on some environment I am not sure. I guess Sharepoint is a bit temperamental.
Thing I would try as well:
Check if there is any workflow doing some work on that item when you check it in
Try to use SystemUpdate() instead of Update() if that suits your requirements
Good luck