138 lines
6.5 KiB
JavaScript
138 lines
6.5 KiB
JavaScript
// ==UserScript==
|
|
// @name Status.io Selector
|
|
// @namespace https://status.io
|
|
// @description Effort to simplify configuration of incidents/maintenance windows
|
|
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
|
|
// @require http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js
|
|
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
|
|
// @grant GM_addStyle
|
|
// @grant GM_setClipboard
|
|
// @include /^https?://app\.status\.io/dashboard/.*$/
|
|
// @version 0.0.1
|
|
// ==/UserScript==
|
|
|
|
const urlRegex = /^http?s:\/\/servicedesk(\.microsoft\.com)?\/\#\/customer\/commercial\?caseNumber=\d+$/
|
|
if (urlRegex.test($("ul").context.URL)) {
|
|
try {
|
|
waitForKeyElements("#mc-case-section", storeAndPrint);
|
|
|
|
function storeAndPrint () {
|
|
var region = "";
|
|
var d = new Date();
|
|
var endDate = d.toISOString().valueOf()
|
|
d.setDate(d.getDate() - 1)
|
|
var startDate = d.toISOString().valueOf()
|
|
const caseText = $("#mc-case-section")[0].innerText;
|
|
const caseID = $("#content")[0].innerText.split('\n')[1]
|
|
const resourceURIRegex = /\/subscriptions\/[\d\w]{8}-[\d\w]{4}-[\d\w]{4}-[\d\w]{4}-[\d\w]{12}\/resourceGroups\/.*\/providers\/Microsoft\.ContainerService\/managedClusters\/.*/g;
|
|
const resourceURI = caseText.match(resourceURIRegex)[0];
|
|
const ascResourceURI = resourceURI.replace(/\//gi, "~2F");
|
|
const subscription = resourceURI.split('/')[2];
|
|
const resourceGroup = resourceURI.split('/')[4];
|
|
const cluster = resourceURI.split('/')[8];
|
|
var template = `
|
|
farts
|
|
|
|
`;
|
|
const regionRegex = /- Location:.*/g;
|
|
const regionlower = caseText.match(regionRegex)[0].split(' ')[2];
|
|
switch (regionlower) {
|
|
case 'australiaeast':
|
|
region = "AustraliaEast";
|
|
break;
|
|
case 'westus2':
|
|
region = "WestUs2";
|
|
break;
|
|
default:
|
|
console.log(`Sorry, looks like ${regionlower} isn't stored as a valid region. Please reach out to tybean@.`);
|
|
}
|
|
const tenantIDRegex = /- Tenant Id:.*/g;
|
|
const tenantID = caseText.match(tenantIDRegex)[0].split(' ')[3];
|
|
const objectIDRegex = /- Object Id:.*/g;
|
|
const objectID = caseText.match(objectIDRegex)[0].split(' ')[3];
|
|
const appLensURL = `https://applens.azurewebsites.net${resourceURI}/home/category?startTime=${startDate}&endTime=${endDate}`;
|
|
const jarvisURL = `https://jarvis-west.dc.ad.msft.net/?page=actions&acisEndpoint=Public&selectedNodeType=3&extension=AzureContainerService%20AKS&group=Resource%20Operations&operationId=GetManagedCluster&operationName=Get%20Managed%20Cluster&inputMode=single¶ms={"wellknownsubscriptionid":"${subscription}","smeaksresourcegroup":"${resourceGroup}","smeaksresource":"${cluster}","smeaksapiversions":"2019-04-01"}&actionEndpoint=${region}`;
|
|
const ascURL = `https://azuresupportcenter.msftcloudes.com/resourceExplorer/resource/${ascResourceURI}?srId=${caseID}`
|
|
var zNode = document.createElement ('div');
|
|
zNode.innerHTML = '<button id="appLensButton" type="button">'
|
|
+ 'AppLens</button><button id = jarvisButton>Jarvis</button><button id=ascButton>ASC</button><button id = kustoButton>Kusto</button> <button id = oneClickButton>1 - Click</button>'
|
|
;
|
|
zNode.setAttribute ('id', 'myContainer');
|
|
document.body.appendChild (zNode);
|
|
|
|
//--- Activate the newly added button.
|
|
document.getElementById ("appLensButton").addEventListener (
|
|
"click", appLensButtonClickAction, false
|
|
);
|
|
document.getElementById ("jarvisButton").addEventListener (
|
|
"click", jarvisButtonClickAction, false
|
|
);
|
|
document.getElementById ("ascButton").addEventListener (
|
|
"click", ascButtonClickAction, false
|
|
);
|
|
document.getElementById ("kustoButton").addEventListener (
|
|
"click", kustoButtonClickAction, false
|
|
);
|
|
document.getElementById ("oneClickButton").addEventListener (
|
|
"click", oneClickButtonClickAction, false
|
|
);
|
|
|
|
function appLensButtonClickAction (zEvent) {
|
|
window.open(appLensURL, "_blank");
|
|
}
|
|
function jarvisButtonClickAction (zEvent) {
|
|
window.open(jarvisURL, "_blank");
|
|
}
|
|
function ascButtonClickAction (zEvent) {
|
|
window.open(ascURL, "_blank");
|
|
}
|
|
function kustoButtonClickAction (zEvent) {
|
|
GM_setClipboard(template, "kusto queries");
|
|
alert(`Kusto queries for ${cluster} have been copied to clipboard!`);
|
|
}
|
|
function oneClickButtonClickAction (zEvent) {
|
|
appLensButtonClickAction(zEvent);
|
|
jarvisButtonClickAction(zEvent);
|
|
ascButtonClickAction(zEvent);
|
|
kustoButtonClickAction(zEvent);
|
|
}
|
|
|
|
//--- Style our newly added elements using CSS.
|
|
GM_addStyle ( multilineStr ( function () {/*!
|
|
#myContainer {
|
|
position: absolute;
|
|
bottom: 0;
|
|
left: 0;
|
|
font-size: 14px;
|
|
background: orange;
|
|
border: 3px outset black;
|
|
margin: 3px;
|
|
opacity: 0.7;
|
|
z-index: 222;
|
|
padding: 5px 5px;
|
|
}
|
|
#myButton {
|
|
cursor: pointer;
|
|
}
|
|
#myContainer p {
|
|
color: red;
|
|
background: white;
|
|
}
|
|
*/} ) );
|
|
|
|
function multilineStr (dummyFunc) {
|
|
var str = dummyFunc.toString ();
|
|
str = str.replace (/^[^\/]+\/\*!?/, '') // Strip function () { /*!
|
|
.replace (/\s*\*\/\s*\}\s*$/, '') // Strip */ }
|
|
.replace (/\/\/.+$/gm, '') // Double-slash comments wreck CSS. Strip them.
|
|
;
|
|
return str;
|
|
}
|
|
}
|
|
} catch (err) {
|
|
// If an error was thrown, go ahead and present it as an alert to help
|
|
// with debugging any problems
|
|
alert(err.toString());
|
|
}
|
|
}
|