#!/usr/bin/python
from hawkAPI.lib.core.hawkcore import hawkcore 
from hawkAPI.lib.core.hawkapi import hawkapi
from hawkAPI.lib.core.hawklib import hawklib
from hawkAPI.lib.plugins.hawkXLSX import hawkXLSX
import argparse
from datetime import datetime
from operator import itemgetter
import inspect
import sys

usage = 'lastseen -u "id" -p "pass" -i "server" -c "client" '
parser = argparse.ArgumentParser(description="XLSX output for client for lastseen",epilog=usage)
parser.add_argument("-u","--user",help="Username",type=str,required=True)
parser.add_argument("-p","--passw",help="Password",type=str,required=True)
parser.add_argument("-i","--server",help="The hawk server IP",type=str,required=True)
parser.add_argument("-c","--client",help="Client name",type=str,required=True)

opt = parser.parse_args()
if len(sys.argv) < 4:
     parser.print_help()
     sys.exit()

hawk = hawkcore(opt.server)
hawk.login(opt.user,opt.passw)
res = hawkapi(hawk)
lib = hawklib(hawk)
data = res.getResByGroup(opt.client)
keys = ["resource_name","os_type_name","resource_group","eps_average","resource_address","last_seen"]

book = hawkXLSX(opt.client + "-Lastseen.xlsx",hawk)
book.addpage("epslastseen",data,nkeys=keys)
book.close()
hawk.logout()
