Solarwinds API Poll Now - network-monitoring

In the SolarWinds user interface, there is a button you can click within a switch or interface view to "Poll Now", instead of waiting for the regularly scheduled poll. I have been trying to figure out a way to recreate this functionality using the SolarWinds API. I've looked through this page, and it seems like I will need to use either the 'invoke' or 'update' operations, but there is almost no information on the actual usage. I have also tried examining the Javascript in the user interface, and can't make heads or tails of it.
I'm wondering if someone can point me towards some useful documentation as to what operations are actually available in the API (the 'invoke' operation requires you to give a 'verb' as an argument, but I can't find any kind of list or documentation as to what verbs are available). Does anyone know of any resources?

If you look at Orion.Nodes SWIS Entity you can see in the bottom "PollNow" SWIS Verb. Unfortunatelly it is not so well documented what parameters it actually has (it can be seen in SWQL Studio though). But you should be able to do it this way using Powershell:
$orionHost = "<hostname where orion is installed>"
$orionUsername = "Admin" # fill login username to orion
$orionPassword = "Pass" # fill login password to orion, this example counts that this is not empty string
$nodeIdToPoll = 1; # put id of the node
$Entity = "Orion.Nodes"
$Verb = "PollNow"
$Data = #($nodeIdToPoll)
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$credentials = new-object PSCredential ($orionUsername , (ConvertTo-SecureString $orionPassword -AsPlainText -Force))
Invoke-RestMethod "https://$($orionHost):17778/SolarWinds/InformationService/v3/Json/Invoke/$Entity/$Verb" `
-Method POST `
-Body (ConvertTo-Json -InputObject $Data) `
-Credential $credentials `
-ContentType "application/json"

Related

How to Get the credentials object without prompt using powershell

I am using the below command,
$SQLServerPSCred = Get-Credential
to get the credential object.
How can I get the Creds object without the Prompt?
I have tried below code, but it is failing.
$SQLServerPSCred = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $Password
You haven't included much information about what your actual problem with the code is. it's correct that you're prompted with your first example. As you explicitly tell it to ask you.
With your second example it's incomplete.
PowerShell – How to create a PSCredential object by koteshblog has an example on how to do it:
$secpasswd = ConvertTo-SecureString "PlainTextPassword" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ("username", $secpasswd)
As you can see you first need to convert the password into a SecureString which you can pass to the credential object. It also shows a slightly different syntax but that shouldn't matter.
Depending on what you're doing and where that script resides it can also be worth it to look into some form of "more secure" storage for your secrets. As it is everyone who would have access to the script could extract the username and password from it.
One option is to store the secure string. But keep in mind a secure string is somewhat tied to the users. So You won't be able to easily just pass along a text file that contains the password.
For an example on how to do that check Powershell Tip – Storing and Using Password Credentials by robcost. It's a basic solutions there might be better ones available depending on your needs.

Is it possible to have a parameter within a parameter when using Invoke-WebRequest?

I'm trying to configure my websites using the integrated API for Incapsula and I've run into a situation where the particular setting I'm trying to configure has it's own parameter that can be set. I'm already using a parameter to pass through with the API call when using Invoke-WebRequest.
If I only want to configure a single setting, the parameter looks like this:
$params = #{account_id='123456';api_id='98765';api_key='furhtjf-adkjoei-ekjmvnt';`
site_id='999999';param='async_validation';value='true'
}
$webRequest = Invoke-WebRequest https://my.incapsula.com/api/prov/v1/sites/performance/advanced `
-Method Post -Body $params
As you can see here in this screenshot there are multiple parameters that I can specify:
I can make an API call for each setting that I want to configure, but that's just not efficient. So, how can I set all of them at the same time?

Migrate Jira tickets to Visual Studio Online

I am currently investigating how to migrate our helpdesk ticket data from JIRA to Visual Studio Online. As a test I used the workflow described below to do an initial import:
Migrate backlog items from ScrumWise to Visual Studio Online?
Unfortunately this does not allow me to change fields like the CreatedDate.
The REST API documentation has a section on how to use the bypassRules parameter that is supposed to enable me to force an update. Below is a simple PowerShell script that I used to try this parameter. Unfortunately it does not seem to work for me.
$username = "<username>"
$password = "<password>"
$basicAuth = ("{0}:{1}" -f $username,$password)
$basicAuth = [System.Text.Encoding]::UTF8.GetBytes($basicAuth)
$basicAuth = [System.Convert]::ToBase64String($basicAuth)
$headers = #{Authorization=("Basic {0}" -f $basicAuth)}
$Endpoint = "https://<domain>.visualstudio.com/defaultcollection/_apis/wit/workitems/12?api-version=1.0&bypassRules=true"
$Body = '[{"op": "add", "path": "/fields/System.CreatedDate", "value":"2007-01-01T00:00:00Z"}]'
$ContentType = "application/json-patch+json"
Invoke-RestMethod -Uri $Endpoint -headers $headers -Method Patch -Body $Body -ContentType $ContentType
The request completes with a success return code but the fields are not updated.
I double checked and am certain that I'm added to the "Project Collection Services Account" group.
Update: the bypassRules parameter works when I create a new work item instead of updating one.
Is there anybody that has had a similar issue and managed to get things working for work item updates?

Powershell WCF Response (Headers and Cookies)

Using Powershell, how do I connect to a WCF web service using New-WebServiceProxy, and retrieve the response header information including cookie data? I have scoured the net and can't find any relevant information, other than stepping away from use of New-WebServiceProxy.
My current PS script looks like...
$authSvc = New-WebServiceProxy –Uri ‘http://myserver/Services/AuthenticationService.svc?WSDL’
$LoginResults = $true
$authSvc.Login('user1', 'abc123', $null, $true, $true, [ref] $LoginResults, [ref] $null)
... Seems there must be additional hooks into the New-WebServiceProxy that expose the header data, but I can't seem to identify it. Using C# (just a test console app), I have been able to invoke this web service and retrieve cookie data, so I know the service is functioning correctly.
Thoughts?
OK - I think I have an answer to my own question. Placing here for others trying the same thing.
The trick is to use the CookieContainer object which is intrinsic to the New-WebServiceProxy object. The CookieContainer has a CookieCollection in it. This collection can be enumerated. Elaborating on my example in the question, I show how to expose cookie information returned from the web service call...
$authSvc = New-WebServiceProxy –Uri ‘http://myserver/Services/AuthenticationService.svc?WSDL’
$authSvc.CookieContainer = New-Object System.Net.CookieContainer
$LoginResults = $true
$authSvc.Login('user1', 'abc123', $null, $true, $true, [ref] $LoginResults, [ref] $null)
$CookieCollection = $authSvc.CookieContainer.GetCookies(‘http://myserver/Services/AuthenticationService.svc?WSDL’)
foreach($cookie in $CookieCollection)
{
echo $cookie.Name
echo $cookie.Value
}
If I use the Get-Member method of the service...
$authSvc | Get-Member
... I then can see all the exposed methods the service allows. The CookieContainer happens to be one of these. Other relevant properties exposed are (but not limited to)...
ClientCertificates
Credentials
RequestEncoding
SoapVersion
Url
UserAgent

Using Twitter API on shared server - Rate limit exceeded even though I am caching the response

I have written a php script which gets the latest status update for 12 different twitter accounts by pulling an xml for each and caching it on my server. This currently runs every 30 minutes.
Unfortunately I keep getting the "Rate limit exceeded. Clients may not make more than 150 requests per hour." error event though i'm only making 24 requests from the 150 I should have.
I assume this is because my domain is on a shared server and twitter is counting other requests against me.
How can I authorise my requests so i'm not restriced by the standard IP limit?
I have no experience of OAuth so need step by step instructions if possible.
Thanks in advance!
OK so I managed to get the most of this working with no previous experience of API's etc.
Here is my step by step guide:
Step 1.
Create a Twitter list.
Go to: https://twitter.com/username/lists
Click "Create list"
Enter details and save.
Go to a twitter user you wish to add to the list and click the gear dropdown and select "Add or remove from lists". Tick the checkbox next to your list.
Step 2.
Create a Twitter App via: https://dev.twitter.com/apps/new
Log in using your Twitter credentials.
Give your app a name, description etc.
Go to the Settings tab and change the Access type to Read and Write then click "Update this Twitter application's settings".
Click "Create my access token" at the bottom of the page.
You will now have a Consumer Key, Consumer secret, Access token and Access token secret. Make a note of these.
Step 3. Create API tokens.
Download and install onto your server the Abraham Twitter oAuth library from: https://github.com/abraham/twitteroauth (I'll use a folder called "twitter").
Create a new file, name it authorise.php in the oAuth folder and put the following code inside (with your generated keys in place of the named text). (Put the code between < ? PHP and ?> brackets).
// Create our twitter API object
require_once("twitteroauth/twitteroauth.php");
$oauth = new TwitterOAuth('Put-Consumer-Key-here', 'Put-Consumer-secret-here',
'Put-Access-Token-here', 'Put-Access-token-secret-here');
// Send an API request to verify credentials
$credentials = $oauth->get("account/verify_credentials");
echo "Connected as #" . $credentials->screen_name;
// Post our new "hello world" status
$oauth->post('statuses/update', array('status' => "hello world"));
This has now authorised your twitter App for the API and posted a "hello world" status on your twitter account.
Note: The Read / Write access change we did earlier alowed the code to post the status update, it's not actually needed to pull the list from the API but I did it to make sure it was working OK. (You can turn this off again by going back to the Settings).
Step 4.
Create PHP file to pull your list and cache the file.
Create an XML file (YOUR-FILE-NAME.xml) and save it in the oAuth folder.
Create a PHP file (YOUR-PHP-FILE.php) and save it in the oAuth folder
Edit the below code with your twitter API keys, file name and twitter list details and save it in your PHP file. (Put the code within < ? PHP and ?> brackets).
/* Twitter keys & secrets here */
$consumer_key = 'INSERT HERE';
$consumer_secret = 'INSERT HERE';
$access_token = 'INSERT HERE';
$access_token_secret = 'INSERT HERE';
// Create Twitter API object
require_once('twitteroauth/twitteroauth.php');
// get access token and secret from Twitter
$oauth = new TwitterOAuth($consumer_key, $consumer_secret, $access_token, $access_token_secret);
// fake a user agent to have higher rate limit
$oauth->useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9';
// Send an API request to verify credentials
$credentials = $oauth->get('account/verify_credentials');
echo 'Connected as #' . $credentials->screen_name . '\n';
// Show API hits remaining
$remaining = $oauth->get('account/rate_limit_status');
echo "Current API hits remaining: {$remaining->remaining_hits}.\n";
$ch = curl_init();
$file = fopen("YOUR-FILE-NAME.xml", "w+");
curl_setopt($ch, CURLOPT_URL,'https://api.twitter.com/1/lists/statuses.xml?slug=INSERT-LIST-NAME&owner_screen_name=INSERT-YOUR-TWITTER-USERNAME-HERE&include_entities=true');
curl_setopt($ch, CURLOPT_FILE, $file);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($file);?>
Copy the file path into your browser and test it. (e.g. http://www.yourwebsite.com/twitter/YOUR-PHP-FILE.php)
This should contact twitter, pull the list as an XMl file and save it into YOUR-FILE-NAME.xml. Test it by opening the XML file, it should have the latest statuses from the users in your twitter list.
Step 5.
Automate the PHP script to run as often as you like (up to 350 times per hour) via a Cron job.
Open your Cpanel and click "Cron jobs" (usually under Advanced).
You can choose the regularity of your script using the common settings.
In the command field add the following code:
php /home/CPANEL-USERNAME/public_html/WEBSITE/twitter/YOUR-PHP-FILE.php >/dev/null 2>&1
Your script will now run as often as you have chosen, pull the list from twitter and save it into YOUR-FILE-NAME.xml.
Step 6.
You can now pull statuses from the cached XML file meaning your visitors will not be making unnecessary calls to the API.
I've not worked out how to target a specific screen_name yet if anyone can help there?
a) don't check 12 different accounts, create a [public] list https://twitter.com/lists and check only the it => 12 times less requests
b) use this awesome oAuth lib: https://github.com/abraham/twitteroauth and use oAuth requests instead of unsigned => you will get 350 requests and they will not be affected by IP limit