Jump to content


Photo
- - - - -

simplest way to archive HAI Omni event logs using HH?


  • Please log in to reply
27 replies to this topic

#1 js19707

js19707

    Dedicated Cocooner

  • -=Gold Supporter=-
  • 191 posts
  • Location:SF Bay Area
  • Experience:average
  • Software:CQC
  • Hardware:HAI OmniPro II
  • Tech:UPB, RadioRA2
  • Audio:Nuvo
  • Video:Windows Media Center
  • CCTV:ip

Posted 03 March 2012 - 04:21 AM

I'm looking for the best way to reliably archive the event logs from my OP2. i had posted a similar question back in December and lupinglade suggested using HH. i recently got a machine set up w/ HH for this purpose, but haven't got the event logging up and running.

my request for help in the other thread didn't a response and i couldn't figure out how to move it to the Haiku/Haikuhelper subforum where it would get more attention from those who can help, i'm posting again here (note to mods: it would be great if you could combine these two threads)

I tried writing the following script but it doesn't appear to properly retrieve the events. the fields are all 'undefined', even though if I go to http://localhost/api/controller.events i get back data that looks correct.

thanks!




var isCollectingEvents = false;
var lastCollectionTS = 0;
function onRefreshConfig(forced) {
  controller.refreshEvents();
}
function onSyncStart(forced, timestamp) {
  if(!isCollectingEvents) collectEvents();
}
function collectEvents() {
  if(controller.isConnected) { // don't log nonsense if not connected
	isCollectingEvents = true;
	var line = '';
	var count = 0;
	var firstEventSeen = 0;
	var lastEventSeen = 0;
	var collectionTS = controller.date;
	var events = controller.events;
	for (var i in events) { // events are most-recent first
	  var e = events[i];
	  if (e.dateIsValid && e.date <= lastCollectionTS) {
		break;
	  }
	  line+= e.dateDescription + ": " + e.eventDescription + "\n";
	  count++;
	  if (lastEventSeen == 0) {
		lastEventSeen = e.date;
	  }
	  firstEventSeen = e.date;
	}
			  
	lastCollectionTS = collectionTS;
	helper.logToExternalFile('EventLog.txt', count + " events between ["
	  + firstEventSeen + " - " + lastEventSeen + "] collected at "
	  + lastCollectionTS);
	helper.logToExternalFile('EventLog.txt', line);
	helper.log(controller, count + " events between [" + firstEventSeen
	  + " - " + lastEventSeen + "] collected at " + lastCollectionTS);
	setTimeout('collectEvents()', 10*60*1000); // Every 10 minutes
  }
  else {
	isCollectingEvents = false;
  }
}


#2 lupinglade

lupinglade

    Cocoonut

  • Manufacturers
  • PipPipPipPip
  • 1084 posts
  • Experience:guru
  • Software:Custom
  • Hardware:HAI OmniPro II
  • Tech:UPB, ZigBee, Custom
  • Audio:Nuvo
  • Video:AirPlay
  • CCTV:ip, dvr
  • Phone:Linksys PAP2, Vonage

Posted 03 March 2012 - 11:59 AM

I've traced it down to a bug in HaikuHelper causing this, we've corrected it and the next update will work. I will help you get it adjusted as you need.

Edited by lupinglade, 03 March 2012 - 12:00 PM.


#3 lupinglade

lupinglade

    Cocoonut

  • Manufacturers
  • PipPipPipPip
  • 1084 posts
  • Experience:guru
  • Software:Custom
  • Hardware:HAI OmniPro II
  • Tech:UPB, ZigBee, Custom
  • Audio:Nuvo
  • Video:AirPlay
  • CCTV:ip, dvr
  • Phone:Linksys PAP2, Vonage

Posted 03 March 2012 - 12:05 PM

The script will likely need a few more tweaks because controller.refreshEvents() should be called AND completed before each time you examine the events, so that you analyze the latest ones. I'll push the next update to Apple today, which will include the fix needed.

#4 lupinglade

lupinglade

    Cocoonut

  • Manufacturers
  • PipPipPipPip
  • 1084 posts
  • Experience:guru
  • Software:Custom
  • Hardware:HAI OmniPro II
  • Tech:UPB, ZigBee, Custom
  • Audio:Nuvo
  • Video:AirPlay
  • CCTV:ip, dvr
  • Phone:Linksys PAP2, Vonage

Posted 03 March 2012 - 12:21 PM

Something along these lines will do what you want once the update is out. Notice i've adjusted the event refresh to happen each time before you start recording them. Queue checkpoints help you sequence it correctly. Now you can set the refresh interval to whatever you like (where its 10 minutes currently), but likely running it every 10 minutes is inefficient and would burden the controller. You can also adjust controller.refreshEvents(0) to a different number than 0 if you only want the last x events to be checked each time, likely there is no sense in refreshing all events every time as that many events can't accumulate so quickly (hopefully).

var isCollectingEvents = false;
var lastCollectionTS = 0;
 
function onSyncStart(forced, timestamp) {
  if(!isCollectingEvents) collectEvents();
}
 
function collectEvents() {
  if(controller.isConnected) { // don't log nonsense if not connected
	isCollectingEvents = true;
	helper.log(controller, "Refreshing Events...");
	controller.refreshEvents(0);
	controller.addQueueCheckpoint("EventsRefreshed");
  } else {
	isCollectingEvents = false;
  }
}
 
function onQueueCheckpointReach(checkpoint) {
  if(checkpoint == "EventsRefreshed") recordEvents();
}
 
function recordEvents() {
  helper.log(controller, "Recording Events...");
  var line = '';
  var count = 0;
  var firstEventSeen = 0;
  var lastEventSeen = 0;
  var collectionTS = controller.date;
  var events = controller.events;
 
  for (var i in events) { // events are most-recent first
	var e = events[i];
	if (e.dateIsValid && e.date <= lastCollectionTS)  break;
	line+= e.dateDescription + ": " + e.eventDescription + "\n";
	count++;
	if (lastEventSeen == 0) lastEventSeen = e.date;
	firstEventSeen = e.date;
  }
				
  lastCollectionTS = collectionTS;
  helper.logToExternalFile('EventLog.txt', count + " events between [" + firstEventSeen + " - " + lastEventSeen + "] collected at " + lastCollectionTS);
  helper.logToExternalFile('EventLog.txt', line);
  helper.log(controller, count + " events between [" + firstEventSeen + " - " + lastEventSeen + "] collected at " + lastCollectionTS);
  setTimeout('collectEvents()', 10*60*1000); // Every 10 minutes
}

Edited by lupinglade, 03 March 2012 - 12:24 PM.


#5 js19707

js19707

    Dedicated Cocooner

  • -=Gold Supporter=-
  • 191 posts
  • Location:SF Bay Area
  • Experience:average
  • Software:CQC
  • Hardware:HAI OmniPro II
  • Tech:UPB, RadioRA2
  • Audio:Nuvo
  • Video:Windows Media Center
  • CCTV:ip

Posted 03 March 2012 - 09:00 PM

thanks lupinglade for the fast response (as always!) and the corrections.
i'll keep an eye out for the updated HH release.

#6 heffneil

heffneil

    Dedicated Cocooner

  • Registered
  • PipPipPip
  • 296 posts

Posted 04 March 2012 - 10:45 PM

This is great I was going to ask this question. Perfect timing! Thanks!

I think I would prefer to email my logs that way I can read them from afar and or have them in the"cloud" rather than in a file on the machine should the drive die or whatever! I think I can out that together.

Thanks

Neil

Edited by heffneil, 04 March 2012 - 10:50 PM.


#7 js19707

js19707

    Dedicated Cocooner

  • -=Gold Supporter=-
  • 191 posts
  • Location:SF Bay Area
  • Experience:average
  • Software:CQC
  • Hardware:HAI OmniPro II
  • Tech:UPB, RadioRA2
  • Audio:Nuvo
  • Video:Windows Media Center
  • CCTV:ip

Posted 05 March 2012 - 12:04 AM

i agree with you abt reliability of hard drives. my plan was to write to a RAIDed NAS share and/or to one of the available cloud-replicated drive share services. email isn't a bad way to go but i already have too much email that i don't read :blush:

i was actually going to split the files based upon date and clean up the logic around retrieving the events to reduce the redundancy and load, as lupinglade suggested. i'll do it once the new version of HH is available.

i can post the updated version here if there's interest in it?

#8 heffneil

heffneil

    Dedicated Cocooner

  • Registered
  • PipPipPip
  • 296 posts

Posted 05 March 2012 - 09:40 PM

I a interested so post away. In terms of email it's small ans I have thousands of email. If I need to look back I can search gmail and find what I am looking for. Gmail is a much a repository for stuff as it is for email.

Thanks

Neil

#9 lupinglade

lupinglade

    Cocoonut

  • Manufacturers
  • PipPipPipPip
  • 1084 posts
  • Experience:guru
  • Software:Custom
  • Hardware:HAI OmniPro II
  • Tech:UPB, ZigBee, Custom
  • Audio:Nuvo
  • Video:AirPlay
  • CCTV:ip, dvr
  • Phone:Linksys PAP2, Vonage

Posted 07 March 2012 - 05:08 PM

it would be very easy to change it to do emails instead

#10 heffneil

heffneil

    Dedicated Cocooner

  • Registered
  • PipPipPip
  • 296 posts

Posted 11 April 2012 - 03:41 PM

Can we see an example so I could do this? I want to get this started.

#11 lupinglade

lupinglade

    Cocoonut

  • Manufacturers
  • PipPipPipPip
  • 1084 posts
  • Experience:guru
  • Software:Custom
  • Hardware:HAI OmniPro II
  • Tech:UPB, ZigBee, Custom
  • Audio:Nuvo
  • Video:AirPlay
  • CCTV:ip, dvr
  • Phone:Linksys PAP2, Vonage

Posted 11 April 2012 - 03:51 PM

This should do e-mails:

var isCollectingEvents = false;
var lastCollectionTS = 0;
 
function onSyncStart(forced, timestamp) {
  if(!isCollectingEvents) collectEvents();
}
 
function collectEvents() {
  if(controller.isConnected) { // don't log nonsense if not connected
		isCollectingEvents = true;
		helper.log(controller, "Refreshing Events...");
		controller.refreshEvents(0);
		controller.addQueueCheckpoint("EventsRefreshed");
  } else {
		isCollectingEvents = false;
  }
}
 
function onQueueCheckpointReach(checkpoint) {
  if(checkpoint == "EventsRefreshed") recordEvents();
}
 
function recordEvents() {
  helper.log(controller, "Recording Events...");
  var line = '';
  var count = 0;
  var firstEventSeen = 0;
  var lastEventSeen = 0;
  var collectionTS = controller.date;
  var events = controller.events;
 
  for (var i in events) { // events are most-recent first
		var e = events[i];
		if (e.dateIsValid && e.date <= lastCollectionTS)  break;
		line+= e.dateDescription + ": " + e.eventDescription + "\n";
		count++;
		if (lastEventSeen == 0) lastEventSeen = e.date;
		firstEventSeen = e.date;
  }
								
  lastCollectionTS = collectionTS;
 
  var message = count + " events between [" + firstEventSeen + " - " + lastEventSeen + "] collected at " + lastCollectionTS + "\n";
  message += line;
  helper.sendMail(controller, "[email protected]", "Event report", message);
 
  setTimeout('collectEvents()', 10*60*1000); // Every 10 minutes
}

Of course this will email you every 10 minutes, so don't forget to adjust that appropriately.

Edited by lupinglade, 11 April 2012 - 03:52 PM.


#12 heffneil

heffneil

    Dedicated Cocooner

  • Registered
  • PipPipPip
  • 296 posts

Posted 11 April 2012 - 03:57 PM

How often should I do it? I mean I would think once at noon and once at midnight is more than sufficient?

Sorry im a noob and never really good at javascript without hacking it to bits!

#13 lupinglade

lupinglade

    Cocoonut

  • Manufacturers
  • PipPipPipPip
  • 1084 posts
  • Experience:guru
  • Software:Custom
  • Hardware:HAI OmniPro II
  • Tech:UPB, ZigBee, Custom
  • Audio:Nuvo
  • Video:AirPlay
  • CCTV:ip, dvr
  • Phone:Linksys PAP2, Vonage

Posted 11 April 2012 - 03:58 PM

There is a problem with this script however as it looks like the message to be sent is too large and our server will not allow it through. We'll have to look at either increasing the message size limit or letting HaikuHelper do the actual e-mailing directly using your own SMTP server.

#14 lupinglade

lupinglade

    Cocoonut

  • Manufacturers
  • PipPipPipPip
  • 1084 posts
  • Experience:guru
  • Software:Custom
  • Hardware:HAI OmniPro II
  • Tech:UPB, ZigBee, Custom
  • Audio:Nuvo
  • Video:AirPlay
  • CCTV:ip, dvr
  • Phone:Linksys PAP2, Vonage

Posted 11 April 2012 - 04:02 PM

Then you would set it to every 12 hours I suppose, or you can adjust the script to do it exactly at a given time. I can write up a sample to do that. The only problem right now is what I mentioned above... we use a very basic e-mailing system right now, I guess we will need to expand it for large messages like these.

#15 js19707

js19707

    Dedicated Cocooner

  • -=Gold Supporter=-
  • 191 posts
  • Location:SF Bay Area
  • Experience:average
  • Software:CQC
  • Hardware:HAI OmniPro II
  • Tech:UPB, RadioRA2
  • Audio:Nuvo
  • Video:Windows Media Center
  • CCTV:ip

Posted 12 April 2012 - 12:44 AM

i hesitate to ask this, but.. if you're going to have to do work to create a more flexible email solution anyway.. it would be really great if you could support sending email via Gmail or Yahoo , i.e. SMTP authentication plus either TLS/STARTTLS or SSL (see http://support.googl...en&answer=13287 and http://help.yahoo.co...pop/pop-33.html). this is probably more reliable and fewer headaches long-term than having to relay SMTP yourself (which i guess is what HH does now?). rather than have to implement yourself, i presume there are open source implementations available under reasonable license terms but honestly i've never looked. at any rate, i figure there's no harm in asking..




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users