New to LM: How do I refer to the local filesystem in an embedded PowerShell script of a DataSource?
How do I refer to the local filesystem in an embedded PowerShell script of a DataSource? The below works fine from a PowerShell session console on a Collector server, but fails when running embedded in LogicMonitor. The Active Directory LogicMonitor service account is in the local Administrators group on the Resource server (a LM Collector server in this), same as my admin account using the PowerShell session. It also has explicit NTFS "Full Control" rights on the folder in the path variable below.
Do I have to use the Get-PSDrive cmndlet? Or is there a simple way to do it when running embedded in the LogicMonitor environment?
-Steve
SteveDahlberg
Posted 1 year ago·Last reply 1 year ago
59 comments
SteveDahlberg
OP1 year agoOne HUGE unresolved question for me is, in a DataSource definition, when you set Active Discovery "Discovery Schedule" setting to "Only when host/DataSource added or changed", does "changed" mean when you run Manual Discovery on the resource ( my assumption) and NEVER anytime else? Or does "changed" mean that it can sense when the DataSource has been updated and that triggers it to run even in the Manual setting?
Mike Moniz
·1 year agoThe documentation seems to only say "it can be configured to execute only when the DataSource is initially applied to a device, or when the Datasource (or the device it applies to) is updated in some way."
I would take that as more than just manually kicking off AD, and likely covers things like updating the device's ip, name, categories, and such. But that is a guess as I never tested that myself. I would assume it might just run as some random time and not rely on it not running.
SteveDahlberg
OP1 year agoOur LM person who handed this task over to me (and I'm glad for it because I've learned a ton about LM in the past weeks), was strongly under the impression that the setting was that AD would run ONLY if the user manually ran it, and therefore I thought the same, and the wording of the option is compatible with that. However, once I got into creating this DataSource, I definitely noticed felt it had run unexpectedly a few times, so I realized that technically that setting wording could also be interpreted more ambiguously.
So it's interesting to hear you say that. I wish I knew for sure about the items you mention, but primarily also whether any of the following could potentially trigger Active Discovery even with that setting applied:
A script updating a property on a resource-level or instance-level property?
Manually creating or editing a resource's property?
Saving changes to the script in the DataSource, but not running "Force DataSource Re-Match" or "Run Active Discovery"?
Same but with doing the "Force DataSource Re-Match" but not "Run Active Discovery"?
-Steve
Mike Moniz
·1 year agoI never really used that option so never really thought of it as a possible 100% manual process. It might not even been an option when I started using LM (unsure), which may be why it didn't really come up.
You may want to reach out to LM support or your rep to see if they can provide more technical details on exactly when it runs.
SteveDahlberg
OP1 year agoI forgot to say that this is mainly for testing and also so I can gain a better understanding of how it really works, so I would rely on it in general. But part of "doing it right" involves learning why things are generally done a certain way. I'm making good progress with this stuff and have a more detailed understanding of it day by day, but at times it stalls out and I feel I'm just poking around in the dark at it, seeing what happens.
SteveDahlberg
OP1 year agoWow, it's really acting up. Maybe it will post my comment this time. I missed whatever answer you gave because it just showed up as "undefined" (like my previous attempt did a minute ago). I will say this, though:
I have it working with the ###auto.whateverproperty notation in Active Discovery and in reading property values (at the instance level). Even though I can't set a resource-level property when processing instances in the script, is it possible to read those properties' values?
But my bigger question right now is: Is there any way to manually create and populate an instance-level custom auto property on an existing instance prior to the script updating it, or (without API calls) can it only be created/updated from the Active Discovery script?
SteveDahlberg
OP1 year agoArgh, it should have been: ####auto.whateverproperty in the Active Discovery output.
SteveDahlberg
OP1 year agoSteveDahlberg
OP1 year agoFor some reason I'm unable to start a new discussion right now, just says:
Cannot add message
Something went wrong, please try again,
But I've been stumped on the following issue and it's driving me nuts:
How do I read the values of instance-level properties in an embedded PowerShell DataSource Collection script? Or resource-level properties in an embedded PowerShell PropertySource? I understand how to write properties and their values in the Active Discovery script with something like
I have an instance-level custom property "auto.AssignedCollectorDeviceName" on a resource instance that I would like to check the value of during Collection script execution, and create my key-value pair for script output based on that value. But I can't for the life of me figure out how to reference and check the host resource's properties while the script is running.
Also, my first thought was to have the custom property ("AssignedCollectorDeviceName" in that case) at the resource level, and check it while the Collection scripts runs, but realized I (don't think) I can read a resource-level property in that case, only instance-level properties, but I can't even figure out how to do that (without using the API). So in addition to using the auto property at the instance-level, maybe a PropertySource would be better? I'd like to learn how to make and use one, but in its script I think I would have the same problem of reading the value of resource property in order to do the logic to form the script output.
Mike Moniz
·1 year agoMike Moniz
·1 year agoThe forum are having more problems :P
You should be able to read any resource property from either AD or Collection script by doing $Prop = '##auto.AssignedCollectorDeviceName##' just like you can use $Host = '##SYSTEM.HOSTNAME##'. Just note that if the property does not exist, it will not get replaced, so you might want to add code that looks something like this
But for an instance property, I haven't tried to pull that myself. If I needed the same information that the AD script had, I would just put the same code into the Collection script. Since 90% of the DataSources scripts I've done has been BatchScripts, many times the AD and Collector scripts are identical except that it has an "IsAD" true/false flag that branches what it outputs at the end.
In general, you should only put in items related to the specific instance into the instance property. If you have information that is specific to the device itself, I do suggest you use a PropertySource instead.
For example, for a disk space check, you might want to have auto.filesystem=ntfs or auto.removable=true at the instance-level since they can change per instance. But if you want to set something like auto.TotalSataPorts=4 would be better to put in a ProperySource since it's about the device and not each drive.
SteveDahlberg
OP1 year agoThanks, Mike. And yes, that stumped me for the longest time, but a few weeks ago when looking through other DataSource scripts in LM, I saw that they just used a flag at top, and that's what I've been doing for a while now.
Most of this I had questions about is working, but right when it seems so close, I'm trying to force a new datapoint to alert based on a key-value pair with value=1 (like I use in some other datapoints in this DataSource that work fine), but it isn't working.
On the raw data page for the instance in question, "Poll Now", it clearly shows it's sending a 1 to this new datapoint and NaN to the rest, but when I close that and look at the Raw Data table, it shows "NoData" in the column for that datapoint. Any idea what could cause that? It's configured identically to similar datapoints in the DataSource, but what could be changing the value from 1 to NoData between "Poll Now" and the Raw Data table?
- Steve
Mike Moniz
·1 year agoIf you can provide a screenshot of the full Poll Now screen and the No Data table showing the issue.
Also double check that Range for that datapoint. Blank min/max means no mix/max (so ok to leave blank) but make sure it's not considering the value out of range.
SteveDahlberg
OP1 year agoI resolved it a bit ago by forcing the script in Collection mode to send a 1 to the datapoint. But yes, there was a strange disconnect. Anyway, there is what I noted this morning after doing that, and I was literally about to post this question:
What could cause an alert to hang on once the underlying cause in the instance has quit notifying the datapoint from the Collection script? Alert history shows it alerted once last night then stopped, which is correct (was a test). Collection is not sending it any data, none shown received in Raw Data or Poll Now, and I confirmed with debug outputs that the block that can send 1 to the datapoint is not being executed, but still it won't clear. However, it cleared immediately when I forced-sent 0 to it.
Mike Moniz
·1 year agoIf I understand you right. A NoData will not clear an alert. So if your threshold is >=5 and the data is (over time) 1, 1, 1, 6, NoData, NoData, 2, 2, 1, 1... the "6" will cause an alert but it will not clear that alert until it gets a valid value under the threshold. So NoData is not a condition that will clear the alert until it gets the "2" which can then clear it (assuming instant alert/clear).
SteveDahlberg
OP1 year agoThanks, Mike. Yes, I may just have to have the old and new DataSource up in adjacent tabs and just bludgeon my way through it. Hey, I haven't tried using ##INSTANCE##, I will definitely investigate that! I've got it working in the meantime by populating the instance Description field in the Active Discovery script with the literal path (to the textfile) and then referencing ##DESCRIPTION## in the custom alert messages. But if I can you ##INSTANCE##, it seems less kludgy that using the description field for that.
SteveDahlberg
OP1 year agoMike, you've been so helpful; I really appreciate it. Quick question about your last example, which relates to one of the two general questions I have below: What are the implications of having the DataSource setting "Use Wildvalue as Unique Identifier" enabled in the context of your example?
---
Two very general questions right now (keep in mind I only dove into all of this starting a few weeks ago; I didn't even know what a DataSource was, lol, but now I've built and re-built the one I'm working on several time, have complex datapoints going in this multi-instance DataSource, etc):
1. Regarding the DataSource setting "Use Wildvalue as Unique Identifier", I wish I could turn it off for this module, but I understand you cannot once it's enabled (due to dependencies or something?). I tried cloning the DataSource but I still couldn't disable it in the clone. But at this point, with the DataSource fairly developed, I cringe at the thought of having to recreate it from scratch just to change that one thing. What do people normally do in this situation?
2. I wonder what the mechanics are behind the WILDALIAS token not being available for use in custom alert messages? The list of available tokens is quite extensive, but WILDALIAS isn't one of them, which I discovered when I tried to use it but it always just came back as text "##WILDALIAS##".
Mike Moniz
·1 year agoYou can try exporting the DataSource, edit the json directly, then delete/re-import. I normally would just rebuild, but when I'm developing I save the datapoints and graphs for last, so normally it's not to bad to do some copy/pasting.
In the context of my example, it wouldn't matter what that option is set to since neither WildValue or WildAlias will change on multiple calls.
I guess I didn't really pay that much attention to that "Use Wildvalue as Unique Identifier" and that seems to work backwards then I thought. WildValue is suppose to be the ID with the WildAlias as the "display name" of the instance. That option didn't exist when I started doing DSes so that's kinda confusing why it's saying that alias was the id. But really I don't dynamically change either value so for me I might have never noticed it. I would suggest using WildValue as the ID.
I think ##INSTANCE## would be equivalent to ##WILDALIAS##.
Mike Moniz
·1 year agoI think you need a step back a bit a get a better understanding of how Script and BatchScript DataSources works. I suggest watching some of the videos in LM Academy like https://academy.logicmonitor.com/introduction-to-datasources and reading over the docs like https://www.logicmonitor.com/support/logicmodules/datasources/data-collection-methods/scripted-data-collection-overview and https://www.logicmonitor.com/support/logicmodules/datasources/data-collection-methods/batchscript-data-collection and https://www.logicmonitor.com/support/logicmodules/datasources/data-collection-methods/scripted-data-collection-overview. Also highly suggest you look at existing DataSources to understand how it works like Microsoft_DHCP_IPv4Scopes. Look at the examples at https://www.logicmonitor.com/support/terminology-syntax/scripting-support/embedded-powershell-scripting
Suggest working out answers to questions like:
For example LogicMonitor will tell you what device it wants information on, you don't tell it.
Here is an example of a BatchScript DataSource, if you wanted to implement getting disk usage of all the drives on a device.
ActiveDiscovery: Get the name of the device from LM by looking at ##SYSTEM.HOSTNAME## and sent a query to that device asking for the list of all drives. Output something like this:
Collection: Get the name of the device from LM by looking at ##SYSTEM.HOSTNAME## and send a query to that device asking for the list of all drives along with the usage information. Output something like this:
When LM later on wants to get the information for the free space of the D: drive, it will set the ##WILDVALUE## to "D" and extract all the lines that start with "D." then pull the totalspace, freespace, and usedspace.
Your script should only provide output for the device that LM is requesting data on. You would get that information from a line like this:
SteveDahlberg
OP1 year agoOops, forgot about that, it's below. The marked-out box is the same FQDN I explained above. Also, keep in mind, this all works perfectly from a PS session on the controller server where the text file is - File Not Found triggering FileUploadError01, everything. When running embedded in LM though, Active Discovery is in play, and this seems to be part of the problem. It just converts the value 1 to NoData somewhere after script output but before the polling data (it doesn't do this for SystemUptimeError01 when it HAS the list to work from in Collection and it hits an error doing something for a given instance when iterating through the list):
SteveDahlberg
OP1 year agoOh, and yes, if I copy the WILDVALUE param from the top and search the page, it finds it in the Raw Request/Response area below).
Mike Moniz
·1 year agoThe ##WILDVALUE## should be "C-_ps_SocialDistortion-txt" it to match. I guess I wasn't looking to close to what you said before, but what is the FQDN used for? If it's referring to the device your polling, you don't need to provide that in the output. LM will know what device to match your script with.
Your Poll Now should look something like this:
SteveDahlberg
OP1 year agoOh my, suddenly I'm confused all over again. Maybe I'm not understanding what the Raw Request/Response actually means or where that data comes from: I thought it showed that below for whatever datapoints ErrMsg I expand above, but I see now it applies to all of them no matter what. That cleaned up path that you see in that box for ScriptOutput is what I thought it should be grabbing for the FileLoadError01 datapoint with key "##WILDVALUE##.FileLoadError01" , but it applies to all of them, so, where in the world is it getting it from and how do I get the WILDVALUE to be the cleaned up path that I'm writing in the key-value pair and not the name of the instance (which I thought was WILDALIAS anyway)?
SteveDahlberg
OP1 year agoAnd yes, normally it DOES refer to the device being polled (from the list in the main loop that iterates through them), but in this case of File Not Found, this is at the beginning of the script, where it checks and determines it can't find the textfile to read from, writes the key-value pair to output, then exits. In this case, it's still thinking the WILDCARD should be the name of the instance, rather than the cleaned-up path info (which is later used in a custom alert message).
SteveDahlberg
OP1 year agoNow it is back to non-existent list file in Collection, and here is the expanded ErrMsg from Poll Now window (I blacked out the FQDN but note that there is a dot separating the FQDN and datapoint name FileLoadError01, and it's a standard FQDN with no spaces or anything, just <servername>.<subdomain>.<ourdomain.edu>). FileLoadError01=1, and we see this in the "Test Collection Script" output.
The exact same setup works fine for triggering the SystemUptimeError01 datapoint when it's iterating through the list and fails at something, the only difference here is that in this case (although all instances are there in Active Discovery from the in-script list), there's no list to iterate through because it checks for File Not Found (and doesn't find one in this case) before proceeding, and if so, writes that key-value pair to the FileLoadError01 datapoint and exits. That expanded ErrMsg about Param not found is also what you see in any datapoint column when it really SHOULD be showing NoData and correctly not reporting or triggering.
Mike Moniz
·1 year agoCan you show the bottom half of the Poll Now window? That should show the data it got along which what it attempted to pull.
The error message says it can't find the line that matches xxxxx.FileLoadError01=#. In the Poll Now window try to copy the param (the xxxxx.FileLoadError01 thing) to the clipboard, then paste it into the in-page search in the browser to see if it shows up exactly char-for-char in the bottom half of the Poll Now, in the output section. If it does show it there but LM is still not pulling it in, you may need to work with LM support to look at your specific datasource in your portal.
Mike Moniz
·1 year agoActually I'm not sure what you mean here.
NaN and NoData are the same thing. If you want LM to report NoData in a script DataSource, you would just not provide that data by skipping that line in the output (or I guess providing a non-number would be equivalent). But I'm assuming your output does contain xxxxx.FileLoadError01=1 and LM is not finding that line for some reason.
SteveDahlberg
OP1 year agoYes, that's exactly right, I just don't output anything. When I say NoData, that what shows in the Poll Now table, rather than NaN.
SteveDahlberg
OP1 year agoOh that's right, I forgot about that. Let me set it back to the non-existent file in Collection and I'll do that. And just to finish off the snapshot from above, on those lines where you can see it switched from normal operation to all NoData across all datapoints when I set it to a non-existent file, here is the key-value pair output (intended to have a value of 1 to trigger the FileLoadError01 alert) from "Test Collection Script" (I left the instance name off the top since it contains specific information in our environment):
SteveDahlberg
OP1 year agoAnd here is the Poll Now on that same page:
Mike Moniz
·1 year agoYou can also click on the "Show Full ErrMsg" link to see what it says caused the NaN/NoData.
SteveDahlberg
OP1 year agoThis is a screenshot of the polling results for one of the instances (currently coming from the in-script list to avoid any issues with File Not Found in Active Discovery) where in Collection the list textfile doesn't exist, and it detects that and Write-Host's the key-value pair `C-_ps_SocialDistortion-txt.FileLoadError01=1`, which shows up correctly in "Test Collection Script", and yet, it shows as NoData for that datapoint rather than a value of 1. You can even see where it was running and reporting normally until I switched the Collection script to attempt to read from a non-existent textfile, and all the datapoints go to NoData, which they should since there's no way to continue on to the loop and iterate through the instances. HOWEVER, unlike with the SystemUptimeError01 datapoint where it correctly shows 1 in the polling results, in this File Not Found situation it just shows NoData, when it needs to be 1 in order to trigger the alert:
Mike Moniz
·1 year agoClick on the "Poll Now" button and grab a screenshot of that, especially the bottom half as it will show what it pulled and what it's looking for.
SteveDahlberg
OP1 year agoI cleaned the textfile path reference up before using Write-Host, and as before, it shows exactly what you would expect in "Test Collection Script" for File Not found: the same key-value pair as above in the code box, but this time with a cleaned (but fictitious) path. Still, even though the output targets the standard datapoint FileError01 with a value of 1, and you can see it when testing the Collection script, by the time it's listed in the Raw Data polling results for any of the instances (for now I'm using the in-script list for Active Discovery to remove any consideration of File Not Found in AD), it doesn't show 1 in the FileLoadError01 column, but NoData.
I'm basically back to being stumped as to why one works that way and the other doesn't.
Mike Moniz
·1 year agoCan you take a screenshot of running Poll Now of that DataSource under the device on the Resource page? That might give a better clue what LM is attempting to do.
SteveDahlberg
OP1 year agoThat was it - exit 1, rather than return 1. Works as you described, and same with just displaying the error string.
BUT, now that the instances are preserved (yay!), when collection runs (every 5 minutes), my error-handling datapoint FileLoadError01 (for File Not Found) doesn't trigger an alert like it was doing before. Relevant bits are below, and I can see in Test Collection Script in the DataSource that it is indeed returning the correct output, but still when I look at the Raw Data tab for an instance, you can see where the normal flow of data stopped a few cycles ago, and now it's just NoData, which makes sense, since the main loop never starts to iterate through instances, because it bails once it sees it can't find the file. But whereas before that worked perfectly, now in the Raw Data tab, even though the collection script is sending the correct information to the FileLoadError01 datapoint, it's not triggering, because the raw data is ALSO showing NoData in the FileLoadError01 column.
It's like something is intervening after the script output but before or inside the datapoint, and converting "C:\ps\SocialDistortion.txt.FileLoadError01=1" to NoData, which wasn't happening before when I fed Active Discovery the in-script list of instances, but in Collection it's trying to read from the textfile. It worked fine there. But having Active Discovery (even though it's no longer removing the instances from LM) encounter a path with a fictitious file, something seems to convert the correct script output to NoData for the intended datapoint:
Mike Moniz
·1 year agoYou have invalid charaters in WINDVALUE, can't have "\" or ":" in there:
https://www.logicmonitor.com/support/logicmodules/datasources/data-collection-methods/batchscript-data-collection
SteveDahlberg
OP1 year agoThis may be exactly what I'm looking for, since there is already granular error checking and reporting in the Collection script, but if Active Discovery (set to Manual) encounters a missing text file, then it removes all instances, and so the error-handling datapoints are essentially muted, since there are no instances to operate on. If I can even get Active Discovery to just do nothing if the file is not found, leaving the instances intact, then I think it would all work.
But, I can't seem to make it work, so far anyway. In the section where it has determined it can't locate the file at that path, if I can't write to one of my error-handling datapoints here when it's running for Active Discovery (that was my first thought, then I figured you can't do that, and you confirmed it in your last response), instead of the normal WILDVALUE##WILDALIAS Write-Host, I was returning the strings you see below. That way at least there's an instance for the error (with those as its name), indicating something's wrong. And I changed "return" to "return 1". But it was still removing all the instances. So I thought maybe I should populate nothing into the WILD tokens while returning 1, but it still deleted all the instances. I really hope I'm missing something easy here, because I think this would be the easy solution!
Mike Moniz
·1 year agoYou can try "Exit 1" instead of "Return 1" to make sure it's exiting the whole script with exitcode 1. https://www.logicmonitor.com/support/logicmodules/datasources/active-discovery/script-active-discovery
"If the script output is empty or malformed, but the script exits with a code of 0, all previously discovered instances will be removed. To prevent Active Discovery from removing instances in the case of a script error (such as an SNMP timeout), make sure your code is designed to catch such conditions and return a non-zero exit code."
Also you can still write-host before exiting, but you don't need to try to format the error message using x##xxxx##xx and just output the error message straight. LM shouldn't be attempting to interpret it unless you exitcode 0 (or no exitcode) You would only see it when using the test button anyway.
You may want to look at some of the existing DataSources to see how other checks works. For example Microsoft_Windows_Cluster_Nodes shows code like this when there is an autodiscover failure:
SteveDahlberg
OP1 year agoTo continue on with issues reading from a local text file (now that it's working), now I am stumped by a related issue: it all works fine in the embedded PS Collection script when the file is found, but I'm not sure how to handle a "file not found" situation in the Active Discovery script, where the reading from the list also comes into play.
When the file exists, right now it correctly outputs values for Active Discovery in the format "<WILDVALUE>##<WILDALIAS>". But when the text file NOT found, I'm not sure what to do (other than stuff a text string into those two tokens) to indicate File Not Found in a way that Active Discovery can process, and ideally trigger an alert in some way (like you can in Collection during polling). I just don't know enough yet about how LogicMonitor works to know what the possibilities are. Any ideas?
I suppose while I'm at it, I should also ask if there is a better way than using a script for Active Discovery to feed it the contents of a list to use during Active Discovery, but it all works fine as is, as long as the text file is found.
Mike Moniz
·1 year agoI don't think you covered what this DataSource is actually doing. I don't normally see people read files to pull instances, usually it's more direct detection, but still valid way to do it.
But in general. If your script runs into a problem where it's not able to detect instances, you should return an error and set an exit code this is not 0. This will tell LM that there was a problem and to just keep the instances as-is. If you return nothing with exit code 0, LM might think that all the instances are gone and might remove them from LM.
ActiveDirectory problems will not cause alerts, so you want to do something in the DataPoint section instead to report an issue. Perhaps have a DataPoint called "ADFileOK" that returns a 0 if the file is ok or 1 if it's not ok. Something like that. But again I'm trying to be really generic, that specific thing you are checking might have something more obvious.
SteveDahlberg
OP1 year agoThank you so much! I will check these out. Lots to learn on the fly. Was pulled in mainly to write the embedded PS script and get it working properly, but it's gotten more involved, which is fine, because it takes a project my teammate's plate and I've suddenly had a deep dive into certain aspects of LogicMonitor.
SteveDahlberg
OP1 year agoWow. Thank you. I'm still trying to get used to that aspect of it. I didn't even realize that collectors are just DataSources (I just assumed it was a service running on collector servers or on the LM platform somehow). Three quick questions:
How would I go about checking if a device is being monitored by its own collector, and if not, which one is monitoring it?
Conversely, how do I tell which other collector devices a given collector is monitoring?
Finally, where does the configuration take place that defines these arrangements between collectors and collector servers?
Mike Moniz
·1 year agoSorry, I might be confusing things a bit. They are windows services.
You can check which collector is being used for any device/resource by checking the "system.collectordesc" or "system.collectorid" property on the INFO tab of the device. Collectordesc/id is the collector actively being used.
You can also look at Settings > Collectors, and each collector will have a Resources tab which will show you what devices/resources that collector is handling. You can also do bulk moving of devices between collectors from here.
P.S. In LM, "Devices" and "Resources" are the same thing. LM changed the name "Devices" to a more appropriate "Resources" sorta recently, so we tend to use them interchangeably.
SteveDahlberg
OP1 year agoThat was exactly it: The script is actually running on a different Collector server, so for now anyway, I dropped that textfile folder there and it works. Thank you.
But now I'm confused, because as I looked at some of the Collector servers, they were all being monitored by other Collector servers, and that makes me think that you don't want a Collector monitoring its own server, because if the server goes down, so does the Collector that's reporting on it. On the other hand, I (think) you were saying that it's actually best practice to have them be the same, so I'm having trouble reconciling those two. But then again, I'm relatively new to LM, and especially new to this aspect of it. What do you think about this setup?
-Steve
Mike Moniz
·1 year agoSo the Collector DataSources (like Collector Heartbeat, Collector JVM Status, etc) all assume they are running on the same collector as the device itself. It will report on the same system if the collector it not monitoring itself:
"Note: Collector DataSources only monitor the device’s preferred Collector (as established in the device’s configurations). The preferred Collector should be the Collector that is installed on that device. Otherwise, the Collector’s metrics will display on the wrong host. For example, if you attempt to monitor Collector A using Collector B (installed on a separate host), then Collector B’s metrics will display in lieu of Collector A’s on Collector A’s host."
https://www.logicmonitor.com/support/collectors/collector-management/monitoring-your-collector
Personally, I would suggest making sure collector are monitoring itself. If the collector does go down, you will get a separate Collector Down (LMA#) alert so you will still know if there is an issue.
If you follow the normal wizard way of adding a collector device by checking the "Monitor the device on which the collector is installed" that should automatically set the Collector device to use itself as the collector. But if you add the collector device in other ways that might cause it to be monitored by another collector, or there might be other factors.
Mike Moniz
·1 year agoI mean "It will report on the wrong system if the collector it not monitoring itself"
Mike Moniz
·1 year agoYes, and you see it worked for me in my screenshot with a full path. The only thing I'm aware of that LM will do to a powershell script is do a search-and-replace of ##TOKEN## but I didn't see any of that in your code. Even your error message isn't show the path getting screwed up and it's powershell telling you the file doesn't exist there.
I would 100% make sure the script is actually running on the server you think it's running on. Does "Write-Output $env:computername" show the name of the server with the file?
SteveDahlberg
OP1 year agoThat's funny, I was doing something similar for other environmental variables, just to confirm it was indeed running as our LogicMonitor service account, and what the working directory was. But I will try those things. I will point that your last suggestion "Try just Test-Path "C:\JCC-Local_Text_Files\LM-VM_FQDN_List.txt" and see what that returns" - that's exactly what I did to generate that last screenshot of Test Collection Script. And you can see the PowerShell error that's captured on stdError - it lists the path and says it can't find it.
Let me absolutely confirm that using an absolute path like "C:\JCCC-Local_Text_Files\LM-VM_FQDN_list.txt" should be sufficient in an embedded Collection script to reference a local resource like this? Again, it works perfectly as is from a PS session on that collector server.
Mike Moniz
·1 year agoI suggest simplifying the problem to the smallest you can and also do some sanity checks. For example just have the script only Write-Output $env:computername and make sure the script is running on the computer you think it's running on. Then use gc c:\ to see if it can list the JCCC folder. Then gc C:\JCC-Local_Text_Files\ to see files in that folder. If that is all good, then simplify the script. Try just Test-Path "C:\JCC-Local_Text_Files\LM-VM_FQDN_List.txt" and see what that returns. Basically debug the script a part at a time, within LM using the Test button.
SteveDahlberg
OP1 year agoAlso, I just additionally inserted the below 2 lines of code right at the beginning of the function to get a direct output with the layer of error reporting, and here is a screen shot of the Test Collection Script - do my absolute paths look okay? Anything else provide a clue?
Mike Moniz
·1 year agoAlso verify that the collector assigned to the device you are testing against is the same one with the file. LM will let you monitor a collector device using a completely different collector, although you should never do that (it will throw the collector DSes off). But something that isn't hard to mistakenly do. I usually set the collector device to use 127.0.0.1 specifically to help catch that.
Aka if you have servers Collector01 and Collector02, make sure that the collector assigned to Collector01 is Collector01 (itself). LM will let you monitoring Collector01 using Collector02.
SteveDahlberg
OP1 year agoMike, Yeah, the textfile is on one of our Collector servers, and that is what we're using to monitor. Keep in mind, this all works fine in a PS session on the Collector server, it finds the local path, it all works. Just not in LogicMonitor, here are some screenshots below. In this case, the actual test of the textfile path and determination of the result happens in a function that attempts to find and read the contents of the file (a simple list of text, one per line). It's called from the main loop and passed the (previously-assigned) value of:
$VM_FQDN_Path = 'C:\JCCC-Local_Text_Files\LM_FQDN-VM_list.txt'
Here a screenshots (in order) of the function that attempts to read the textfile and load its contents, that function being called from the main script and the corresponding output (using Write-Host), and finally, the results in LogicMonitor from using Test Script on the Collection script:
SteveDahlberg
OP1 year agoShoot, was hoping it would paste them in, not create download attachment links. Let me see if I can just paste them:
Mike Moniz
·1 year agoShouldn't need to do anything special to reference local system. I'm not able to replicate the issue myself. Can you get a screenshot of a minimum script and Test output like my working test below?
Mike Moniz
·1 year agoI'm not clear where the text file you want to pull is. Is the file on the server running the collector software or on a different system?
Scripts will always run from the collector. So if the file is in another system, you would need to write your script to have it connect and pull the file. That might be using something like \\server\c$ or doing a Invoke-Command to run powershell commands on the remote system.
If it is local to the collector server, what does the Test Button/Poll Now show? What kinda LM script is this? Part of a ConfigSource? DataSource?
SteveDahlberg
OP1 year agoI believe most of that is answered in my post. But to be clear, the .txt textfile is (for now anyway) at the absolute path "C:\JCCC-Local_Text_Files\my_testfile.txt" on one of our collector servers where I've been developing the script. It works fine from a PowerShell session on the collector server. But so far, I can't get it to see the file (so I can read from it in the script, like I do when the same script runs in PS session on the collector server). This is in a DataSource.
I use `Test-Path $textFilePath` in the script to make sure it's there, works fine, but when running embedded in LM, it always reports that it can't find it at that absolute path location. I even tried copying it to "C:\Program Files\LogicMonitor\Agent\bin\JCCC-Local_Text_Files" but that didn't work, then I tried just the text file itself at that location (rather than the containing folder), but no joy. The LogicMonitor service account is in the local admins group on this Windows server, and has "Full Control" explicitly granted on the folder in question, although it shouldn't need it I wouldn't think.
I'm relatively new to this, and it feels like I'm missing the proper way to refer to the local filesystem (if it's different than what I showed above with Test-Path above. I'm totally stuck.
-Steve