I have the following Azure Function that fails with Access is Denied (ignore the fact that the logic is all weird, I'm just doing a first test)
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);
}
If I change the lines
PingReply reply = pingSender.Send(hostName, timeout);
return reply.Status == IPStatus.Success;
to return true;
for the sake of testing, the function runs well.
What do I need to configure so the function can do the ping?