lesleyxyz / node-firewalla

The node-firewalla package is a NodeJS module which allows you communicate with your Firewalla box
MIT License
15 stars 1 forks source link

Device Status is missing from host entry. #1

Open eodabas opened 10 months ago

eodabas commented 10 months ago

Hello,

I am developing a snippet to detect the presence of a device to be able to use with Home Assistant. I can get the host information but I couldn't find any specific information for a device status (online/offline) in the object.

The code I use is:

import { SecureUtil, NetworkService, FWGroup, FWGroupApi, HostService } from 'node-firewalla'

SecureUtil.importKeyPair("etp.public.pem", "etp.private.pem")
let { groups } = await FWGroupApi.login()
let fwGroup = FWGroup.fromJson(groups[0], "192.168.11.1")

let hostService = new HostService(fwGroup)
let hosts = await hostService.getAll()

hosts.hosts.forEach(device => {
  if (device.localDomain == "my-mobile") {
    console.log(device);
  }
});

and the output is:

{
  dtype: { human: 0 },
  ip: '192.168.11.159',
  ipv6: [ 'fe80::xx:xx:xxxx:2612' ],
  mac: '5C:3E:xx:xx:xx:xx',
  lastActive: 1699888693.743,
  firstFound: 1699282309.51,
  macVendor: 'Apple, Inc.',
  recentActivity: '{"ts":1699888418.46,"category":"social"}',
  dhcpName: 'my-mobile',
  userLocalDomain: '',
  localDomain: 'my-mobile',
  intf: '244d8797-e019-4595-b041-ba8356ad1b7e',
  stpPort: 'eth3',
  bname: 'my-mobile',
  names: [ 'my-mobile' ],
  policy: {
    unbound: { state: false },
    family: false,
    safeSearch: { state: false },
    monitor: true,
    doh: { state: false },
    vpnClient: { profileId: '' },
    adblock: false,
    device_service_scan: false,
    acl: true,
    ipAllocation: { allocations: [Object] },
    qos: true,
    devicePresence: false,
    deviceOffline: false,
    tags: [ '4' ]
  },
  tags: [ '4' ],
  flowsummary: { inbytes: 1235212141, outbytes: 389085481 },
  stale: false,
  openports: { lastActiveTimestamp: 1699868826.306, tcp: [ 62078 ] },
  detect: {
    type: 'phone',
    brand: 'Apple',
    model: 'iPhone',
    os: 'iOS',
    feedback: { type: 'phone' }
  }
}

The thing is, I can see the status, whether it is online or offline on the Firewalla app, but the object remains pretty much the same. Am I missing something here, or is it something that node-firewalla not implemented or maybe firewalla API does not provide?

lesleyxyz commented 8 months ago

Hi Eodabas,

Sorry for coming back so late, I didn't notice there was an issue open.

I believe it is the lastActive key in the json you posted. I believe the firewalla app has an inbuild timeout that if it has been less than 30 minutes it considers it as offline.

I will investigate this further.

Kr