Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@azure/ai-anomaly-detector
Advanced tools
An isomorphic client library for the Azure Anomaly Detector service.
Azure AnomalyDetector API enables you to monitor and detect abnormalities in your time series data with machine learning.
Key links:
The AnomalyDetectorClient
provides methods for anomaly detection:
detectEntireSeries
- Detects anomalies on an entire data setdetectLastPoint
- Detects anomalies in the latest data pointdetectChangePoint
- Evaluates change point score of every series pointSee our support policy for more details.
If you use the Azure CLI, replace <your-resource-group-name>
and <your-resource-name>
with your own unique names:
az cognitiveservices account create --kind AnomalyDetector --resource-group <your-resource-group-name> --name <your-resource-name>
@azure/ai-anomaly-detector
packageInstall the Azure Anomaly Detector client library for JavaScript with npm
:
npm install @azure/ai-anomaly-detector
AnomalyDetectorClient
To create a client object to access the Anomaly Detector API, you will need the endpoint
of your Anomaly Detector resource and a credential
. The Anomaly Detector client can use either Azure Active Directory credentials or an API key credential to authenticate.
You can find the endpoint for your Anomaly Detector resource in the Azure Portal by clicking Keys and Endpoint
under Resource Management in the menu or by using the Azure CLI snippet below:
az cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query "endpoint"
Use the Azure Portal to browse to your Anomaly Detector resource and retrieve an API key by clicking Keys and Endpoint
under Resource Management, or use the Azure CLI snippet below:
Note: Sometimes the API key is referred to as a "subscription key" or "subscription API key."
az cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>
Once you have an API key and endpoint, you can use the AzureKeyCredential
class to authenticate the client as follows:
const { AnomalyDetectorClient, AzureKeyCredential } = require("@azure/ai-anomaly-detector");
const client = new AnomalyDetectorClient("<endpoint>", new AzureKeyCredential("<API key>"));
Client API key authentication is used in most of the examples, but you can also authenticate with Azure Active Directory using the [Azure Identity library]. To use the DefaultAzureCredential provider shown below,
or other credential providers provided with the Azure SDK, please install the @azure/identity
package:
npm install @azure/identity
You will also need to register a new AAD application and grant access to Anomaly Detector by assigning the "Cognitive Services User"
role to your service principal (note: other roles such as "Owner"
will not grant the necessary permissions, only "Cognitive Services User"
will suffice to run the examples and the sample code).
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID
, AZURE_TENANT_ID
, AZURE_CLIENT_SECRET
.
const { AnomalyDetectorClient } = require("@azure/ai-anomaly-detector");
const { DefaultAzureCredential } = require("@azure/identity");
const client = new AnomalyDetectorClient("<endpoint>", new DefaultAzureCredential());
This sample demonstrates how to detect change points on entire series.
const { AnomalyDetectorClient, TimeGranularity } = require("@azure/ai-anomaly-detector");
const { AzureKeyCredential } = require("@azure/core-auth");
// You will need to set this environment variables in .env file or edit the following values
const apiKey = process.env["API_KEY"] || "";
const endpoint = process.env["ENDPOINT"] || "";
async function main() {
// create client
const client = new AnomalyDetectorClient(endpoint, new AzureKeyCredential(apiKey));
// construct request
const request = {
series: [
{ timestamp: new Date("2018-03-01T00:00:00Z"), value: 32858923 },
{ timestamp: new Date("2018-03-02T00:00:00Z"), value: 29615278 },
{ timestamp: new Date("2018-03-03T00:00:00Z"), value: 22839355 },
{ timestamp: new Date("2018-03-04T00:00:00Z"), value: 25948736 },
{ timestamp: new Date("2018-03-05T00:00:00Z"), value: 34139159 },
{ timestamp: new Date("2018-03-06T00:00:00Z"), value: 33843985 },
{ timestamp: new Date("2018-03-07T00:00:00Z"), value: 33637661 },
{ timestamp: new Date("2018-03-08T00:00:00Z"), value: 32627350 },
{ timestamp: new Date("2018-03-09T00:00:00Z"), value: 29881076 },
{ timestamp: new Date("2018-03-10T00:00:00Z"), value: 22681575 },
{ timestamp: new Date("2018-03-11T00:00:00Z"), value: 24629393 },
{ timestamp: new Date("2018-03-12T00:00:00Z"), value: 34010679 },
{ timestamp: new Date("2018-03-13T00:00:00Z"), value: 33893888 },
{ timestamp: new Date("2018-03-14T00:00:00Z"), value: 33760076 },
{ timestamp: new Date("2018-03-15T00:00:00Z"), value: 33093515 }
],
granularity: TimeGranularity.daily
};
// get change point detect results
const result = await client.detectChangePoint(request);
const isChangePointDetected = result.isChangePoint.some((changePoint) => changePoint);
if (isChangePointDetected) {
console.log("Change points were detected from the series at index:");
result.isChangePoint.forEach((changePoint, index) => {
if (changePoint === true) {
console.log(index);
}
});
} else {
console.log("There is no change point detected from the series.");
}
// output:
// Change points were detected from the series at index:
// 9
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});
More Samples can be found here
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the AZURE_LOG_LEVEL
environment variable to info
. Alternatively, logging can be enabled at runtime by calling setLogLevel
in the @azure/logger
:
import { setLogLevel } from "@azure/logger";
setLogLevel("info");
For more detailed instructions on how to enable logs, you can look at the @azure/logger package docs.
Please take a look at the samples directory for detailed examples on how to use this library.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.
FAQs
An isomorphic client library for the Azure Anomaly Detector service.
The npm package @azure/ai-anomaly-detector receives a total of 27 weekly downloads. As such, @azure/ai-anomaly-detector popularity was classified as not popular.
We found that @azure/ai-anomaly-detector demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.