示例#1
0
    # set api uri
    #i.e https://<foreman.yourdomain>/api
    # or set environment vairable foreman_apibaseurl
    apiBaseURL = getBaseURL()

    search = "last_report+<+\"35+minutes+ago\"+and+status.enabled+%3D+true"
    msg = "Hosts out of sync:"
    if options.searcherror:
        search = "last_report+>+\"35+minutes+ago\"+and+%28status.failed+>+0+or+status.failed_restarts+>+0%29+and+status.enabled+%3D+true"
        msg = "Hosts in error state:"

    searchurl = apiBaseURL + "/hosts?search=" + search
    if options.debug:
        DEBUG = True
    username = getUsername()
    password = getPasswd(username)
    thepage = getPage(searchurl, username, password)
    if DEBUG:
        print json.dumps(thepage, indent=4)
    print msg
    timenow = datetime.now(pytz.UTC)
    for host in thepage['results']:
        name = host["name"]
        lastreport = host["last_report"]
        if options.json:
            print json.dumps(host, indent=4)
        reporttime = dateutil.parser.parse(lastreport)
        timediff = timenow - reporttime
        print name, "[ " + str(timediff) + " ]"
示例#2
0
	mac = hostdetails["mac"]
	model =  hostdetails["model_id"]
	ip=hostdetails["ip"]
	if ip == None:
	   ip = "None"
	fqdn=name
	host= fqdn.split('.',1)[0]
	hostgroup_name=hostdetails['hostgroup_name']
	if hostgroup_name == None:
		 hostgroup_name = "None"
	model_name=hostdetails['model_name']
	if DEBUG:
		print host 
	
	if options.json:
		print json.dumps(hostdetails,indent=4)
	print fqdn+",",ip,","+hostgroup_name

if __name__ == '__main__':
  hostname=options.hostname
  username=getUsername()
  password=getPasswd(username)
  if options.allhost:
    hostCount=getPage(theurl+"?per_page=1",username,password)['total']
    allHosts=getPage(theurl+"?per_page="+str(hostCount),username,password)
    for host in allHosts['results']:
	showSimpleHostDetails(host)
  else:
	thepage=getPage(theurl+"/"+hostname,username,password)
	showHostDetails(thepage)
示例#3
0
  # set api uri
  #i.e https://<foreman.yourdomain>/api
  # or set environment vairable foreman_apibaseurl
  apiBaseURL=getBaseURL()

  search="last_report+<+\"35+minutes+ago\"+and+status.enabled+%3D+true"
  msg="Hosts out of sync:"
  if options.searcherror:
  	search="last_report+>+\"35+minutes+ago\"+and+%28status.failed+>+0+or+status.failed_restarts+>+0%29+and+status.enabled+%3D+true"
  	msg="Hosts in error state:"

  searchurl=apiBaseURL+"/hosts?search="+search
  if options.debug:
  	DEBUG=True
  username=getUsername()
  password=getPasswd(username)
  thepage=getPage(searchurl,username,password)
  if DEBUG:
    print json.dumps(thepage,indent=4)
  print msg
  timenow=datetime.now(pytz.UTC)
  for host in thepage['results']:	
		name = host["name"]
		lastreport = host["last_report"]
		if options.json:
			print json.dumps(host,indent=4)
		reporttime = dateutil.parser.parse(lastreport)
		timediff = timenow - reporttime
		print name, "[ "+str(timediff)+" ]"