func (i *Ilo) Syslog(cfg *cfgresources.Syslog) (err error) {
	var port int
	enable := 1
	if cfg.Server == "" {
		msg := "Syslog resource expects parameter: Server."
		i.log.V(1).Info(msg, "step", helper.WhosCalling())
		return errors.New(msg)
	}
	if cfg.Port == 0 {
		i.log.V(1).Info("Syslog resource port set to default: 514.", "step", helper.WhosCalling())
		port = 514
	} else {
		port = cfg.Port
	}
	if !cfg.Enable {
		enable = 0
		i.log.V(1).Info("Syslog resource declared with disable.", "step", helper.WhosCalling())
	}
	remoteSyslog := RemoteSyslog{
		SyslogEnable: enable,
		SyslogPort:   port,
		Method:       "syslog_save",
		SyslogServer: cfg.Server,
		SessionKey:   i.sessionKey,
	}
	payload, err := json.Marshal(remoteSyslog)
	if err != nil {
		msg := "Unable to marshal RemoteSyslog payload to set Syslog config."
		i.log.V(1).Info(msg,
			"IP", i.ip,
			"Model", i.HardwareType(),
			"step", helper.WhosCalling(),
			"Error", internal.ErrStringOrEmpty(err),
		)
		return errors.New(msg)
	}
	endpoint := "json/remote_syslog"
	statusCode, response, err := i.post(endpoint, payload)
	if err != nil || statusCode != 200 {
		msg := "POST request to set User config returned error."
		i.log.V(1).Info(msg,
			"IP", i.ip,
			"Model", i.HardwareType(),
			"endpoint", endpoint,
			"step", helper.WhosCalling(),
			"StatusCode", statusCode,
			"response", string(response),
			"Error", internal.ErrStringOrEmpty(err),
		)
		return errors.New(msg)
	}
	i.log.V(1).Info("Syslog parameters applied.", "IP", i.ip, "Model", i.HardwareType())
	return err
}
Syslog applies the Syslog configuration resource
Syslog implements the Configure interface
package ilo
import (
	"encoding/json"
	"errors"
	"fmt"
	"github.com/bmc-toolbox/bmclib/cfgresources"
	"github.com/bmc-toolbox/bmclib/devices"
	"github.com/bmc-toolbox/bmclib/internal"
	"github.com/bmc-toolbox/bmclib/internal/helper"
)
var _ devices.Configure = (*Ilo)(nil)
func (i *Ilo) Resources() []string {
	return []string{
		"user",
		"syslog",
		"license",
		"ntp",
		"ldap_group",
		"ldap",
		"network",
		"power",
		"https_cert",
	}
}
func (i *Ilo) ApplyCfg(config *cfgresources.ResourcesConfig) (err error) {
	if i.sessionKey == "" {
		msg := "Expected sessionKey not found, unable to configure BMC."
		i.log.V(1).Info(msg,
			"IP", i.ip,
			"Model", i.HardwareType(),
			"step", "Login()",
		)
		return errors.New(msg)
	}
	return nil
}
func (i *Ilo) isRoleValid(role string) bool {
	validRoles := []string{"admin", "user"}
	for _, v := range validRoles {
		if role == v {
			return true
		}
	}
	return false
}
func userExists(user string, usersInfo []UserInfo) (userInfo UserInfo, exists bool) {
	for _, userInfo := range usersInfo {
		if userInfo.UserName == user || userInfo.LoginName == user {
			return userInfo, true
		}
	}
	return userInfo, false
}
func ldapGroupExists(group string, directoryGroups []DirectoryGroups) (directoryGroup DirectoryGroups, exists bool) {
	for _, directoryGroup := range directoryGroups {
		if directoryGroup.Dn == group {
			return directoryGroup, true
		}
	}
	return directoryGroup, false
}
func (i *Ilo) User(users []*cfgresources.User) (err error) {
	existingUsers, err := i.queryUsers()
	if err != nil {
		msg := "Unable to query existing users"
		i.log.V(1).Info(msg,
			"IP", i.ip,
			"Model", i.HardwareType(),
			"step", "applyUserParams",
			"Error", internal.ErrStringOrEmpty(err),
		)
		return errors.New(msg)
	}
	for _, user := range users {
		var postPayload bool
		if user.Name == "" {
			msg := "User resource expects parameter: Name."
			i.log.V(1).Info(msg, "step", "applyUserParams")
			return errors.New(msg)
		}
		if user.Password == "" {
			msg := "User resource expects parameter: Password."
			i.log.V(1).Info(msg, "step", "applyUserParams", "Username", user.Name)
			return errors.New(msg)
		}
		if !i.isRoleValid(user.Role) {
			msg := "User resource Role must be declared and a must be a valid role: 'admin' OR 'user'."
			i.log.V(1).Info(msg, "step", "applyUserParams", "Username", user.Name)
			return errors.New(msg)
		}
		userinfo, uexists := userExists(user.Name, existingUsers)
		userinfo.SessionKey = i.sessionKey
		if user.Enable {
			userinfo.RemoteConsPriv = 1
			userinfo.VirtualMediaPriv = 1
			userinfo.ResetPriv = 1
			userinfo.UserPriv = 1
			userinfo.Password = user.Password
			if user.Role == "admin" {
				userinfo.ConfigPriv = 1
				userinfo.LoginPriv = 1
			} else if user.Role == "user" {
				userinfo.ConfigPriv = 0
				userinfo.LoginPriv = 0
			}
			if uexists {
				userinfo.Method = "mod_user"
				userinfo.UserID = userinfo.ID
				userinfo.UserName = user.Name
				userinfo.LoginName = user.Name
				userinfo.Password = user.Password
			} else {
				userinfo.Method = "add_user"
				userinfo.UserName = user.Name
				userinfo.LoginName = user.Name
				userinfo.Password = user.Password
			}
			postPayload = true
		}
		if !user.Enable && uexists {
			userinfo.Method = "del_user"
			userinfo.UserID = userinfo.ID
			msg := "User disabled in config, will be removed."
			i.log.V(1).Info(msg,
				"IP", i.ip,
				"Model", i.HardwareType(),
				"User", user.Name,
			)
			postPayload = true
		}
		if postPayload {
			payload, err := json.Marshal(userinfo)
			if err != nil {
				msg := "Unable to marshal userInfo payload to set User config."
				i.log.V(1).Info(msg,
					"IP", i.ip,
					"Model", i.HardwareType(),
					"step", helper.WhosCalling(),
					"User", user.Name,
					"Error", internal.ErrStringOrEmpty(err),
				)
				continue
			}
			endpoint := "json/user_info"
			statusCode, response, err := i.post(endpoint, payload)
			if err != nil || statusCode != 200 {
				msg := "POST request to set User config returned error."
				i.log.V(1).Info(msg,
					"IP", i.ip,
					"Model", i.HardwareType(),
					"endpoint", endpoint,
					"step", helper.WhosCalling(),
					"User", user.Name,
					"StatusCode", statusCode,
					"response", string(response),
					"Error", internal.ErrStringOrEmpty(err),
				)
				continue
			}
			i.log.V(1).Info("User parameters applied.",
				"IP", i.ip,
				"Model", i.HardwareType(),
				"User", user.Name,
			)
		}
	}
	return err
}