Esempio n. 1
0
        public CmdbObject GetCmdbObject(int cmdb_id)
        {
            Console.WriteLine("Fetching CMDB Object {0}...", cmdb_id);
            CmdbObject response = JsonRpcCaller.Call <CmdbObject>("cmdb.object.read", new
            {
                apikey = Config.GetInstance().ApiKey,
                id     = cmdb_id
            });

            return(response);
        }
Esempio n. 2
0
        public void CategoryUpdate <T>(CmdbObject obj, T theObject)
            where T : Category
        {
            if (theObject.Constant.Equals("C__CMDB__SUBCAT__STORAGE__DEVICE"))
            {
                CategoryUpdate(obj, theObject, 43);     //Workaround für einen Bug in der i-doit API
                return;
            }
            Dictionary <string, object> updateData = new Dictionary <string, object>();

            updateData.Add("category_id", theObject.id);
            foreach (var fi in theObject.GetType().GetFields())
            {
                //Falls ein Feld mit JsonIgnore gekennzeichnet ist, es ausschließen.
                object[] attribs  = fi.GetCustomAttributes(true);
                bool     ignoreMe = false;
                foreach (object o in attribs)
                {
                    if (o is JsonIgnoreAttribute)
                    {
                        ignoreMe = true;
                        break;
                    }
                }
                if (ignoreMe)
                {
                    continue;
                }

                //Feld in die Update Warteschlage einreihen:
                updateData.Add(fi.Name, fi.GetValue(theObject));
            }

            Console.WriteLine("Updating {0} #{1} in {2}", theObject.DisplayName, theObject.id, obj.title);
            CategoryDeleteResponse r = JsonRpcCaller.Call <CategoryDeleteResponse>("cmdb.category.update", new
            {
                apikey   = Config.GetInstance().ApiKey,
                category = theObject.Constant,
                objID    = obj.id,
                data     = updateData
            });

            if (r.success != 1)
            {
                throw new Exception(r.message);
            }
        }
Esempio n. 3
0
        public void CategoryDelete <T>(CmdbObject obj, string catConstant, int categoryNumber)
            where T : Category
        {
            Console.WriteLine("Deleting {1} #{2} from {0}", obj.title, catConstant, categoryNumber);
            CategoryDeleteResponse cdr = JsonRpcCaller.Call <CategoryDeleteResponse>("cmdb.category.delete", new
            {
                catgID = catConstant,
                cateID = categoryNumber,
                objID  = obj.id,
                apikey = Config.GetInstance().ApiKey
            });

            if (cdr.success != 1)
            {
                throw new Exception(cdr.message);
            }
        }
Esempio n. 4
0
        public void CategoryCreate <T>(CmdbObject obj, T theObject)
            where T : Category
        {
            Console.WriteLine("Adding a {0} to {1}", theObject.DisplayName, obj.title);

            CategoryCreateResponse response;

            if (theObject.Constant.Equals("C__CATG__GLOBAL"))
            {
                response = JsonRpcCaller.Call <CategoryCreateResponse>("cmdb.category.create", new
                {
                    apikey = Config.GetInstance().ApiKey,
                    catgID = 1,
                    objID  = obj.id,
                    data   = theObject,
                });
            }

            if (theObject.Constant.Contains("CATS__"))
            {
                response = JsonRpcCaller.Call <CategoryCreateResponse>("cmdb.category.create", new
                {
                    apikey = Config.GetInstance().ApiKey,
                    catsID = theObject.Constant,
                    objID  = obj.id,
                    data   = theObject,
                });
            }
            else
            {
                response = JsonRpcCaller.Call <CategoryCreateResponse>("cmdb.category.create", new
                {
                    apikey = Config.GetInstance().ApiKey,
                    catgID = theObject.Constant,
                    objID  = obj.id,
                    data   = theObject,
                });
            }

            if (response.success != 1)
            {
                throw new Exception(response.message);
            }
        }
Esempio n. 5
0
        public void SyncList <TCat>(CmdbObject obj, List <TCat> inDb, List <TCat> inMachine)
            where TCat : Category
        {
            //Alle Elemente löschen, die zwar in der Datenbank stehen, aber nicht in der Maschine verbaut sind
            foreach (TCat e in inDb)
            {
                if (!inMachine.Contains(e))
                {
                    CategoryDelete <TCat>(obj, e.Constant, e.id);
                    inDb.Remove(e);
                    SyncList <TCat>(obj, inDb, inMachine);  //Da sich der Enumerator verändert, muss die foreach neu gestartet werden.
                    return;
                }
            }

            //Alle Elemente hinzufügen, die zwar in der Maschine verwendet werden, aber nicht in der Datenbank verzeichnet sind.
            foreach (TCat e in inMachine)
            {
                if (!inDb.Contains(e))
                {
                    CategoryCreate <TCat>(obj, e);
                    inDb.Add(e);
                }
                else
                {
                    //Wenn's schon in der Datenbank steht, dann aktualisieren (sinnvoll bei z.b. Software-Versionen):
                    TCat other = inDb.Find((x) => x.Equals(e)); //Das selbe Element aus der Datenbank rauspicken
                    if (e.IsUpdateNeeded(other))                //unnötigen Netzwerkverkehr vermeiden.
                    {
                        e.id = other.id;
                        CategoryUpdate <TCat>(obj, e);
                    }
                }
            }

            if ((inDb.Count != inMachine.Count) && !typeof(TCat).Equals(typeof(SoftwareAssignment)))
            {
                //TODO: manuellen löscher implementieren
                Console.WriteLine("Problem mit den {0} von {1}, bitte alle {0}s  von {1} in i-doit manuell löschen!",
                                  inDb[0].DisplayName, obj.title);
                return;
            }
        }
Esempio n. 6
0
 protected bool Equals(CmdbObject other)
 {
     return(id == other.id);
 }
Esempio n. 7
0
 public void CategoryUpdate <T>(CmdbObject obj, T theObject, int categoryID) where T : Objects.Category
 {
     throw new NotImplementedException();
 }
Esempio n. 8
0
 public void CategoryDelete <T>(CmdbObject obj, string catConstant, int categoryNumber) where T : Objects.Category
 {
     throw new NotImplementedException();
 }
Esempio n. 9
0
 public void CategoryCreate <T>(CmdbObject obj, T theObject) where T : Objects.Category
 {
     throw new NotImplementedException();
 }
Esempio n. 10
0
 public void SyncList <TCat>(CmdbObject obj, List <TCat> inDb, List <TCat> inMachine) where TCat : Objects.Category
 {
     throw new NotImplementedException();
 }