Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ServiceNow dashboard using PowerShell and WebAPI #66

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6,398 changes: 6,398 additions & 0 deletions servicenow/ServiceNow-Board.json

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions servicenow/ServiceNowIncidents.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#Page time frame query
switch ($timeFrame) {
"last1Hour" { $TimeQuery = "RELATIVEGT@hour@ago@1" }
"last12Hours" { $TimeQuery = "RELATIVEGE@hour@ago@12"}
"last24Hours" { $TimeQuery = "RELATIVEGT@hour@ago@24" }
"last7Days" { $TimeQuery = "RELATIVEGT@dayofweek@ago@7" }
"last30Days" { $TimeQuery = "RELATIVEGT@dayofweek@ago@30" }
"last3Months" { $TimeQuery = "RELATIVEGT@month@ago@3" }
"last6Months" { $TimeQuery = "RELATIVEGT@month@ago@6" }
"last12Months" { $TimeQuery = "RELATIVEGT@month@ago@12" }
}

# Query returns the fields (number, sys_created_on & assignment_group) for all incidents created in the last xx days based on the page time frame
$SNOWQuery = $BaseUrl+"table/incident?sysparm_query=assignment_group.name=ASA^sys_created_on"+$TimeQuery+"&sysparm_display_value=true&sysparm_fields=number%2C%20sys_created_on%2C%20priority"

$Connection = Invoke-RestMethod -Method GET -Uri $SNOWQuery -TimeoutSec 100 -Headers $headers
$Response = $Connection.result
$Results = @()
ForEach ($item in $Response) {
$v = $item.number
$g = $item.priority
$d = Convert-DateEuropeToUS($item.sys_created_on)


$obj = New-Object PSObject
$obj | Add-Member -type Noteproperty -name Value -value $v
$obj | Add-Member -type Noteproperty -name Created_On -value $d
$obj | Add-Member -type Noteproperty -name Priority -value $g
$Results += $obj
}

$Final = $Results | Group-Object -Property Created_On, Priority |
Select-Object @{n='Date'; e={[datetime]::Parse($_.Values[0]) }},
@{n='Name'; e={$_.Values[1] }}, Count

$Final | Select Date, Name, Count


Binary file added servicenow/images/LineGraphTimeFrame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added servicenow/images/PowershellProfile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added servicenow/images/ServiceNow-WebAPI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added servicenow/images/ServiceNowBoad-WebAPI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added servicenow/images/ServiceNowBoad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added servicenow/images/ServiceNowQuery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions servicenow/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# ServiceNow Board
This is a SquaredUp Dashboard that computes WebAPI for ServiceNow and PowerShell to query ServiceNow API.

In our continous improvement to have a "Single Pane of Glass" entry point, we created some ServiceNow Dashboards per teams to have a quick view of current Incidents / Requests / Changes / Problems.

![screenshot](images/ServiceNowBoad.png)


## How to use this dashboard

### Setup a PowerShell Profile
- Navigate to System > PowerShell
- Create new "ServiceNow" Profile as per below

![screenshot](images/ServiceNow-PowerShell-Profile.png)

` $User = 'ServiceNowUser'`
` $Pass = 'Password'`
` $Headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass)))}`
` $Content = 'application/json';`
` $Body = @{};`

` $BaseUrl = "https://<YourInstance>.service-now.com/api/now/"`

> **NOTE:** The function PowerShell **"Convert-DateEuropeToUS"** might not be needed. We have our ServiceNow instance in Europe but our SquaredUp Server in the US.


### Setup a ServiceNow API Integration

Check out the [How To Setup Web API Tile with ServiceNow](https://support.squaredup.com/hc/en-us/articles/4406616264721-How-to-use-the-Web-API-tile-with-ServiceNow)

![screenshot](images/ServiceNow-WebAPI.png)

> **NOTE:** You can name it **"ServiceNow - Prod"** to ease the JSON copy/paste :)


### Setup the dashboard
- Copy the JSON code from [ServiceNow-Board.json](ServiceNow-Board.json)
- Create a new dashboard, select the </> on the top right and paste the content of the .json and click **Apply Changes**.

### Update WebAPI Tiles

- For each WebAPI tiles you might need to adapt your ServiceNow Queries. In that example I'm retrieving only Incidents and Requests for one specifc group.
- Replace "table/incident" with :

`table/sc_request` --> Requests
`table/change_request` --> Changes
`table/problem` --> Problems
`table/cmdb_ci_hyper_v_instance` --> VMs
etc...

![screenshot](images/ServiceNowBoad-WebAPI-Query.png)

### Update PowerShell Tiles

- Select the ServiceNow profile created earlier

![screenshot](images/PowershellProfile.png)

- Update the SNOWQuery in the [ServiceNowIncidents.ps1](ServiceNowIncidents.ps1) based on your needs. *Thanks to SquaredUp support for helping me with the PowerShell!*

![screenshot](images/ServiceNowQuery.png)

- Once all the tiles are working per your needs, click **Publish** and you're done!


> **NOTE:** PowerShell Line graph are Page Time frame based !

![screenshot](images/LineGraphTimeFrame.png)