@azure/arm-monitor
Version:
A generated SDK for MonitorClient.
308 lines • 12.8 kB
JavaScript
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
import { __asyncValues, __awaiter } from "tslib";
import { env, record, isPlaybackMode } from "@azure-tools/test-recorder";
import * as assert from "assert";
import { ClientSecretCredential } from "@azure/identity";
import { MonitorClient } from "../src/monitorClient";
import { LogicManagementClient } from "@azure/arm-logic";
import { StorageManagementClient } from "@azure/arm-storage";
import { EventHubManagementClient } from "@azure/arm-eventhub";
import { OperationalInsightsManagementClient } from "@azure/arm-operationalinsights";
const recorderEnvSetup = {
replaceableVariables: {
AZURE_CLIENT_ID: "azure_client_id",
AZURE_CLIENT_SECRET: "azure_client_secret",
AZURE_TENANT_ID: "88888888-8888-8888-8888-888888888888",
SUBSCRIPTION_ID: "azure_subscription_id"
},
customizationsOnRecordings: [
(recording) => recording.replace(/"access_token":"[^"]*"/g, `"access_token":"access_token"`)
],
queryParametersToSkip: []
};
export const testPollingOptions = {
updateIntervalInMs: isPlaybackMode() ? 0 : undefined,
};
describe("Monitor test", () => {
let recorder;
let subscriptionId;
let client;
let location;
let resourceGroup;
let workflowName;
let storageAccountName;
let namespaceName;
let authorizationRuleName;
let eventhubName;
let workspaceName;
let logProfileName;
let diagnosticName;
let logic_client;
let storage_client;
let eventhub_client;
let op_client;
let workflowsId;
let storageId;
let authorizationId;
let workspaceId;
beforeEach(function () {
return __awaiter(this, void 0, void 0, function* () {
recorder = record(this, recorderEnvSetup);
subscriptionId = env.SUBSCRIPTION_ID;
// This is an example of how the environment variables are used
const credential = new ClientSecretCredential(env.AZURE_TENANT_ID, env.AZURE_CLIENT_ID, env.AZURE_CLIENT_SECRET);
client = new MonitorClient(credential, subscriptionId);
logic_client = new LogicManagementClient(credential, subscriptionId);
storage_client = new StorageManagementClient(credential, subscriptionId);
eventhub_client = new EventHubManagementClient(credential, subscriptionId);
op_client = new OperationalInsightsManagementClient(credential, subscriptionId);
location = "eastus";
resourceGroup = "myjstest";
workflowName = "myworkflowxxx";
storageAccountName = "mystorageaccountyyy";
namespaceName = "mynamespacexxx";
eventhubName = "myeventhubxxx";
workspaceName = "myworkspacexxx";
authorizationRuleName = "myauthorizationRulexxx";
logProfileName = "mylogProfilexxx";
diagnosticName = "mydiagnosticxxxx";
});
});
afterEach(function () {
return __awaiter(this, void 0, void 0, function* () {
yield recorder.stop();
});
});
it("create parameters for diagnosticSettings", function () {
return __awaiter(this, void 0, void 0, function* () {
//workflows.createOrUpdate
const res = yield logic_client.workflows.createOrUpdate(resourceGroup, workflowName, {
location: location,
definition: {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"triggers": {},
"actions": {},
"outputs": {}
}
});
workflowsId = res.id || "";
//storageAccounts.beginCreateAndWait
const storageaccount = yield storage_client.storageAccounts.beginCreateAndWait(resourceGroup, storageAccountName, {
sku: {
name: "Standard_GRS",
},
kind: "StorageV2",
location: "eastus",
encryption: {
services: {
file: {
keyType: "Account",
enabled: true,
},
blob: {
keyType: "Account",
enabled: true,
},
},
keySource: "Microsoft.Storage",
},
tags: {
key1: "value1",
key2: "value2",
}
});
storageId = storageaccount.id || "";
//namespaces.beginCreateOrUpdateAndWait
const namespaces = yield eventhub_client.namespaces.beginCreateOrUpdateAndWait(resourceGroup, namespaceName, { sku: {
name: "Standard",
tier: "Standard",
},
location: location,
tags: {
tag1: "value1",
tag2: "value2",
} });
//namespaces.createOrUpdateAuthorizationRule
const authorization = yield eventhub_client.namespaces.createOrUpdateAuthorizationRule(resourceGroup, namespaceName, authorizationRuleName, { rights: ["Listen", "Send", "Manage"] });
//eventHubs.createOrUpdate
const eventhub = yield eventhub_client.eventHubs.createOrUpdate(resourceGroup, namespaceName, eventhubName, {
messageRetentionInDays: 4,
partitionCount: 4,
status: "Active",
captureDescription: {
enabled: true,
encoding: "Avro",
intervalInSeconds: 120,
sizeLimitInBytes: 10485763,
destination: {
name: "EventHubArchive.AzureBlockBlob",
storageAccountResourceId: "/subscriptions/" + subscriptionId + "/resourceGroups/" + resourceGroup + "/providers/Microsoft.Storage/storageAccounts/" + storageAccountName,
blobContainer: "container",
archiveNameFormat: "{Namespace}/{EventHub}/{PartitionId}/{Year}/{Month}/{Day}/{Hour}/{Minute}/{Second}",
}
}
});
authorizationId = authorization.id || "";
//workspaces.beginCreateOrUpdateAndWait
const workspace = yield op_client.workspaces.beginCreateOrUpdateAndWait(resourceGroup, workspaceName, {
sku: {
name: "PerNode"
},
retentionInDays: 30,
location: location,
tags: {
tag1: "value1"
}
});
workspaceId = workspace.id || "";
});
});
it("diagnosticSettings create test", function () {
return __awaiter(this, void 0, void 0, function* () {
if (isPlaybackMode()) {
this.skip();
}
const res = yield client.diagnosticSettings.createOrUpdate(workflowsId, diagnosticName, {
storageAccountId: storageId,
workspaceId: workspaceId,
eventHubAuthorizationRuleId: authorizationId,
eventHubName: eventhubName,
metrics: [],
logs: [
{
category: "WorkflowRuntime",
enabled: true,
retentionPolicy: {
enabled: false,
days: 0
}
}
]
});
assert.equal(res.name, diagnosticName);
});
});
it("diagnosticSettings get test", function () {
return __awaiter(this, void 0, void 0, function* () {
const res = yield client.diagnosticSettings.get(workflowsId, diagnosticName);
assert.equal(res.name, diagnosticName);
});
});
it("diagnosticSettings list test", function () {
return __awaiter(this, void 0, void 0, function* () {
const res = yield client.diagnosticSettings.list(workflowsId);
});
});
it("diagnosticSettings delete test", function () {
return __awaiter(this, void 0, void 0, function* () {
const res = yield client.diagnosticSettings.delete(workflowsId, diagnosticName);
});
});
it("logProfiles create test", function () {
var e_1, _a;
return __awaiter(this, void 0, void 0, function* () {
if (isPlaybackMode()) {
this.skip();
}
//delete sample logfile
const resArray = new Array();
try {
for (var _b = __asyncValues(client.logProfiles.list()), _c; _c = yield _b.next(), !_c.done;) {
let item = _c.value;
resArray.push(item);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
if (resArray.length >= 1) {
yield client.logProfiles.delete("sample-log-profile");
}
const res = yield client.logProfiles.createOrUpdate(logProfileName, {
location: "",
locations: [
"global"
],
categories: [
"Write",
"Delete",
"Action"
],
retentionPolicy: {
enabled: true,
days: 3
},
storageAccountId: storageId
});
assert.equal(res.name, logProfileName);
});
});
it("logProfiles get test", function () {
return __awaiter(this, void 0, void 0, function* () {
const res = yield client.logProfiles.get(logProfileName);
assert.equal(res.name, logProfileName);
});
});
it("logProfiles list test", function () {
var e_2, _a;
return __awaiter(this, void 0, void 0, function* () {
const resArray = new Array();
try {
for (var _b = __asyncValues(client.logProfiles.list()), _c; _c = yield _b.next(), !_c.done;) {
let item = _c.value;
resArray.push(item);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
}
finally { if (e_2) throw e_2.error; }
}
assert.equal(resArray.length, 1);
});
});
it("delete parameters for diagnosticSettings", function () {
return __awaiter(this, void 0, void 0, function* () {
const workflowDlete = yield logic_client.workflows.delete(resourceGroup, workflowName);
const storageDelete = yield storage_client.storageAccounts.delete(resourceGroup, storageAccountName);
const namespaceDelete = yield eventhub_client.namespaces.beginDeleteAndWait(resourceGroup, namespaceName);
const workspaceDelete = yield op_client.workspaces.beginDeleteAndWait(resourceGroup, workspaceName);
});
});
it("logProfiles delete test", function () {
var e_3, _a;
return __awaiter(this, void 0, void 0, function* () {
const res = yield client.logProfiles.delete(logProfileName);
const resArray = new Array();
try {
for (var _b = __asyncValues(client.logProfiles.list()), _c; _c = yield _b.next(), !_c.done;) {
let item = _c.value;
resArray.push(item);
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
}
finally { if (e_3) throw e_3.error; }
}
assert.equal(resArray.length, 1); //still exist sample logfile
});
});
});
//# sourceMappingURL=monitor_examples.js.map