//processing discovery rule for zabbix public string CVGetClientsForDiscovery() { string json; cvapi api = new cvapi(); api.CVGetClients(); List <cvapi_server> clients = api.CVGetClients(); List <cvapi_server_subclient> srv_subcl_cid = new List <cvapi_server_subclient>(); foreach (cvapi_server client_id in clients) { cv_subclients lst_subclients = api.GetSubClients(Convert.ToInt32(client_id.clientid)); foreach (string sub_client in lst_subclients.lst_subclients) { cvapi_server_subclient new_item = new cvapi_server_subclient { hostname = client_id.hostname, clientid = client_id.clientid, subclient = sub_client }; srv_subcl_cid.Add(new_item); } } json = JsonConvert.SerializeObject(srv_subcl_cid, Newtonsoft.Json.Formatting.Indented); json = json.Replace("\"hostname\"", "\"{#HOSTNAME_CMVLT}\""); json = json.Replace("\"clientid\"", "\"{#CLIENTID_CMVLT}\""); json = json.Replace("\"subclient\"", "\"{#SUBCLIENT_CMVLT}\""); return(json); }
/* * usage: cv_api.exe <client_id> <subclient> * */ static void Main(string[] args) { Config cfg = new Config(); cvapi api = new cvapi(); //api.GetJobsForClient("54", "default"); int x = 0; if ((args.Length > 0) && (Int32.TryParse(args[0], out x))) { if (x > 0) { Console.Write(api.GetJobsForClient(args[0], args[1])); } } else //discovery option { Console.Write(api.CVGetClientsForDiscovery()); } }
//Get job results information for lastday backups public string GetJobs() { //1. Login string token = GetSessionToken(domain, user, pwd); string json = ""; if (string.IsNullOrEmpty(token)) { Debug.WriteLine("Login Failed"); } else { Debug.WriteLine("Login Successful"); cvapi api = new cvapi(); api.CVGetClients(); List <cvapi_server> clients = api.CVGetClients(); List <cvapi_zabbix> lst_cavapi_zbx = new List <cvapi_zabbix>(); foreach (cvapi_server client_ in clients) { string clientPropService = service + "Job?clientId=" + client_.clientid + "&completedJobLookupTime=86400&jobCategory=Finished&jobFilter=backup"; HttpWebResponse ClientResp = SendRequest(clientPropService, "GET", token, null); if (ClientResp.StatusCode == HttpStatusCode.OK) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(ClientResp.GetResponseStream()); var job_summary = xmlDoc.SelectNodes("/JobManager_JobListResponse/jobs/*"); if (job_summary != null) { foreach (XmlNode job in job_summary) { cvapi_zabbix obj = new cvapi_zabbix { server = client_.hostname, status = job.Attributes["status"].Value, totalNumOfFiles = job.Attributes["totalNumOfFiles"].Value, jobId = job.Attributes["jobId"].Value, jobSubmitErrorCode = job.Attributes["jobSubmitErrorCode"].Value, sizeOfMediaOnDisk = job.Attributes["sizeOfMediaOnDisk"].Value, lastUpdateTime = job.Attributes["lastUpdateTime"].Value, percentSavings = job.Attributes["percentSavings"].Value, pendingReason = job.Attributes["pendingReason"].Value, jobElapsedTime = Convert.ToInt64(job.Attributes["jobElapsedTime"].Value), jobStartTime = job.Attributes["jobStartTime"].Value, backupLevelName = job.Attributes["backupLevelName"].Value, pendingReasonErrorCode = job.Attributes["pendingReasonErrorCode"].Value, appTypeName = job.Attributes["appTypeName"].Value, percentComplete = job.Attributes["percentComplete"].Value }; lst_cavapi_zbx.Add(obj); } } } else { Debug.WriteLine(string.Format("Get Client properties request Failed. Status Code: {0}, Status Description: {1}", ClientResp.StatusCode, ClientResp.StatusDescription)); } } json = JsonConvert.SerializeObject(lst_cavapi_zbx, Newtonsoft.Json.Formatting.Indented); } return(json); }