Reaching out to anyone who knows Python (Programming) - Page 1
Forum section: electronics / general

author: Halcyon
author_rank: Unknown
timestamp: July 19, 2017, 09:08:31 am
content: I'm after someone on here who might be more programming-minded than I am to help me with a rather simple project.Basically, I have a Raspberry Pi which I want to turn into a very basic (semi-permanent) network monitor. I started another thread about this, took on-board all the suggestions and tested them. Some failed miserably, others were well and truly over-kill for what I needed.My requirements are these:- I want the RPi to ping a number of IP address (say 3 for good measure); One ping to each host every 20-30 seconds.- I don't care about when the host(s) are UP, rather I need to know ifALLhosts are down (which indicates a total link failure, not just a timeout of one host).- I need to know how long each failure lasts.- It just needs to dump outages to a text file either on the RPi itself (accessible via HTTP or SMB over the local network) or dump it to a network share.I have a Windows application calledNet Uptime Monitorwhich does exactly this, but it's a bit much to leave a Windows box running 24/7 solely for this purpose. It outputs a text file looking like this:Code:8/17/2015 8:44:28 AM Log Start– – – – – – – – – – – – – – – – – – – –Failure Start Length8/17/2015 1:44:25 PM 0:00:448/17/2015 1:49:53 PM 0:00:368/17/2015 1:52:39 PM 0:01:59This is all the information I need to know. It need not alert me in any way, just append it to the text file for when I'm ready to inspect it.Caveats:- I'm asking for help because I'm by no means a software guy. I am an expert in the IT field, just not anything to do with programming.- My knowledge of Linux is very limited, please don't just reply with "Just do it in bash", it doesn't help me in the slightest.- Likewise, I can install Raspbian (or some other flavour of Linux) on the device no problems, anything beyond that, I'm lost when it comes to Linux.- I could spend hours trying to learn this task myself or someone could probably spend 10 minutes doing it for me. I just don't have the time to invest at the moment, but I shall be forever grateful for your assistance and I will contribute a cash donation to Dave on your behalf :-)

author: Ampera
author_rank: Super Contributor
timestamp: July 19, 2017, 09:35:36 am
content: Suggestion: Don't do it in Python.Python is cool and all, and almost completely necessary for GPIO, but I think it may be out of the league of this project.While you said to not tell you to do it in Bash, I am going to suggest bash with some sort of generic command line pinging application that just runs through every so often. It's not hard, and I'd even offer to do it.My strategy when it comes to very very simple languages that I don't know by heart like Bash and Python is to work by reference using generic programming terms. Simple logic statements only really change through syntax, not in basic operation through different languages, so it's fairly easy to figure it all out.If you can figure out a network share on a Raspi I can make a simple program that pings a load of IPs and writes a timestamp of when it goes down, when it comes back up, and the length in between. Just let me know and I'll get started (If you can wait a day or so in order for me to throw up a Debian VM)

author: CJay
author_rank: Super Contributor
timestamp: July 19, 2017, 09:39:35 am
content: If you only care about the link can you not configure SNMP traps to alert on link failure or are your endpoints not 'smart' enough to use SNMP?*ugh, premature posting*There are a few SNMP libraries out there that will work on Pi and are easy to use with Python, you can then gather more than just simplistic link up/down information about remote machines and networks.

author: Halcyon
author_rank: Unknown
timestamp: July 19, 2017, 09:42:09 am
content: Thanks for your reply TwoOfFive, I'm happy to go with your suggestion RE: Bash. What I meant by that comment was, I've had people give me similar advice just assuming that I know Bash just as well as I know DOS commands (which I don't). Ask me to write a DOS batch file that did the same thing, I'd have it done easy enough, Linux is a whole new ballgame for me (which I'm happy to learn... baby steps).My "project" isn't urgent, it can even wait a week or two. I'll just need some assistance in setting it up and getting it going.Quote from: CJay on July 19, 2017, 09:39:35 amI COULD use SNMP but again, it would require a client to receive those traps and then interpret the results. As I mentioned, I don't need to be alerted to the fact a link goes down, I know it's going to go down and I'm powerless to do anything about it, this is about gathering evidence about how often it goes down and for how long, so I can throw it back at the provider and say "here you go, fix it" and not get the old bullshit line "oh it must be your configuration/equipment/Wi-Fi/other bullshit excuse".

author: Ampera
author_rank: Super Contributor
timestamp: July 19, 2017, 09:44:56 am
content: I've already started. We can talk through Skype, or if you want on the PM system. I'm just getting a VM setup now.

author: TerraHertz
author_rank: Super Contributor
timestamp: July 19, 2017, 09:48:24 am
content: You're planning to sue the NBN, aren't you?I sincerely hope you are successful.Did you google "network outage logging utility freeware" ? There seem to be a lot of likely hits, and others wanting to do exactly the same as you.Perhaps something you could run on a small low power single board PC, rather than a raspberry Pi?

author: Halcyon
author_rank: Unknown
timestamp: July 19, 2017, 09:50:39 am
content: Quote from: TerraHertz on July 19, 2017, 09:48:24 amHah not sue, but I've been a right pain in the ass so far (and succeeded somewhat) and am happy to keep going. I have the local member on-side. It's not good enough that NBN Co. have scrapped the FTTN roll-out for new installs, they need to go back and clean up the mess they've already started.I'm a very patient person ;-)The thing is, I have an RPi sitting around doing nothing. I don't have a low-power machine and I don't really need to be buying new hardware just for this. Make use of what I have already.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: July 19, 2017, 09:52:08 am
content: mtrevery 30 seconds via cronand then some text processing?

author: alm
author_rank: Super Contributor
timestamp: July 19, 2017, 09:52:33 am
content: Quote from: TwoOfFive on July 19, 2017, 09:35:36 amWriting a bash script that calls fping would be easy. Calculating the duration would be mildly annoying and would require a good understanding of commands like date(1). I would argue that a language with a native date handling would be easier.Quote from: TwoOfFive on July 19, 2017, 09:35:36 amExcept that bash has barely any built-in functions, so you end up relying on external commands for a lot of the jobs that all have their unique quirks. Plus funny string handling. I would argue that bash is harder to learn than say Python or Ruby if you do not have a good knowledge of the *nix command line (to some extent the same applies to Perl which adopted a bunch of features from the Unix shell and command line utilities).

author: CJay
author_rank: Super Contributor
timestamp: July 19, 2017, 09:54:19 am
content: If they'll accept ping stats as proof then have at it, I once scripted something similar to prove an out of spec run of Cat5 was causing problems (it was almost 200M long and ran past punch presses and two *huge* Trumpf laser cutters), it was sufficient but not very robust and not at all elegant.I like SNMP because it can provide so much more information and it's got me a job or two in the past but, as above, if ping is all you need to prove a point...

author: Halcyon
author_rank: Unknown
timestamp: July 19, 2017, 10:08:44 am
content: Quote from: CJay on July 19, 2017, 09:54:19 amIt's 1000% better than anything they'll get off "regular" users. Usually it's just "oh it's slow, I can't watch my Netflix". They are welcome to come and inspect my configuration if they like, but the Cisco switches and firewalls might put them off a little (I was a network engineer in my previous job, now moved on to less tedious things).Plus if they REALLY wanted to, they could marry up my logs with the alarms they get on their end (but usually ignore) when the line sync drops out.