我有以下 Azure 函数,由于访问被拒绝而失败 (忽略逻辑很奇怪的事实,我只是在做第一个测试)
public static void Run(TimerInfo myTimer, ILogger log)
{
List<string> servers = new List<string>()
{
"server1"
};
foreach(string server in servers)
{
if (!Ping(server))
{
SendEmail($"Server {server} seems down.", log);
}
}
}
static bool Ping(string hostName)
{
Ping pingSender = new Ping();
int timeout = 120;
PingReply reply = pingSender.Send(hostName, timeout);
return reply.Status == IPStatus.Success;
}
static void SendEmail(string message, ILogger log)
{
log.LogInformation(message);
}
如果我改变线路
PingReply reply = pingSender.Send(hostName, timeout);
return reply.Status == IPStatus.Success;
为了return true;测试,该功能运行良好。
我需要配置什么才能让该函数执行 ping 操作?
catspeake
相关分类