I've tried the suggestions of the devs who answered the question but the domain still outputs offline even if they're online.
The domains are from an uploaded csv file which will be listed on the database then output an online or offline status depending on the live status of the domain.
I have a view which should output if the domain on the database is online or offline.
def pingDomain(request, page):
page_object = get_object_or_404(Table, page=page)
try:
subprocess.check_call(['ping', '-c', '1', page_object.page])
except subprocess.CalledProcessError:
host_online = True
else:
host_online = False
context = {
'online': host_online,
}
return render(request, 'home.html', context)
On the…
Top comments (8)
If your end goal is to check website availability, I would suggest making a HEAD request to it, like so:
Here are the advantages:
ping
command in the osping
checks whether the service responds to a ICMP requestIs there any particular reason you've decided to use
subprocess.check_call(['ping', '-c', '1', page_object.page])
?I'm not really sure if you understood what I wanted to output on the template since you've mentioned that my end goal was to check the availability of the website or I'm not sure if you meant online/offline with website availability
I'll definitely try this!
I just saw
on stackoverflow so I used. Big lesson for me to understand code before using it.uhhh this doesn't return the online domains.
Wow :O
OK, at this point I can only suggest two things.
Use breakpoint() to inspect the variables inside the view;
Use this code for your reference: github.com/vergeev/17_sites_monito....
Tell me if something new comes up. :)
Here's what I did
Returns nothing :(
Hi, aside from the logic being incorrect, see the correction in this answer:
answer re: Django view doesn't output correctly
I believe what you're trying to achieve is the following:
Reason being I've changed your logic is because if the…
I see a few additional problems:
some domains, even if online, won't respond to ICMP packets (what
ping
uses for the echo), which means that you'll have false negatives :)another bug in your logic is that it assumes that any type of response from ping, even unreachable domains, will result in the host marked online
I suggest you add a call to
breakpoint()
to the line before thesubprocess
call and check what's going on manuallyHey @rhymes ! Thanks! I'll check on this.