azure - 是否可以阻止来自某些 IP 地址的请求发送到 Application Insights?

标签 azure azure-application-insights

我的客户正在使用 PenTest 工具来测试他在 Azure 中托管的 Web 应用程序。他不希望在 Application Insights 中看到由此生成的异常,因为它们使得查找实际应用程序错误变得非常困难。

是否可以过滤掉来自特定 IP 地址的请求,以便它们不会发送到 App Insights?也许使用遥测处理器之类的东西?我找到了检查请求响应代码等内容的示例,但我似乎找不到如何对 IP 地址执行此操作。

谢谢

最佳答案

如果您知道 IP 地址,则可以使用 TelemetryProcessor

这是代码片段:

public class IPFilter : ITelemetryProcessor
{
    private ITelemetryProcessor Next { get; set; }

    // next will point to the next TelemetryProcessor in the chain.
    public IPFilter(ITelemetryProcessor next)
    {
        this.Next = next;
    }

    public void Process(ITelemetry item)
    {
        // To filter out an item, return without calling the next processor.
        if (!FilterIp(item)) { return; }

        this.Next.Process(item);
    }

    // Example: replace with your own criteria.
    private bool FilterIp(ITelemetry item)
    {
        RequestTelemetry requestTelemetry = item as RequestTelemetry;

        if (requestTelemetry != null && requestTelemetry.Context != null && requestTelemetry.Context.Location != null && !String.IsNullOrEmpty(requestTelemetry.Context.Location.Ip))
        {
            //you can modify the condition as per your requirement
            if (requestTelemetry.Context.Location.Ip == "XXX.XXX.XXX.XXX")
                return false;
        }
        return true;
    }

}

最后,不要忘记注册您的自定义 ITelemetryProcessor。这是official doc供您引用。

关于azure - 是否可以阻止来自某些 IP 地址的请求发送到 Application Insights?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67584268/

相关文章:

c# - Azure Function 应该在错误时记录或抛出异常吗?

azure - 在Appinsigts中,确定查询返回的时间戳是否>24小时前

wpf - 具有 WPF 应用程序的 Application Insights Enterprise 是否将每个用户电脑视为一个节点

Azure ARM 为我们提供了任何检查更改的方法

Azure 可用性测试 - 需要一个指向现有 AI 组件的 'hidden-link' 标记。没有找到

适用于 Service Fabric 的 Azure 应用程序见解

asp.net - Application Insights 扩展破坏了 Azure Web 应用程序

azure - 用于访问 Azure 上的公共(public) RESTServer 应用程序的请求 OAuth2 参数

php - Azure PHP 应用程序和 Azure SQL 数据库

azure - 在 Azure 中为静态网站创建 Web 服务器代理