Exemplo n.º 1
0
        /// <summary>
        /// Utilizes the Get function from STF Library to retrieve results for the given IP Address and OID
        /// </summary>
        /// <returns></returns>
        public string GetSNMPData(out int exeTime, string oid = "")
        {
            string result = string.Empty;

            GetLastError = string.Empty;
            exeTime      = 0;

            if (!string.IsNullOrEmpty(oid))
            {
                OID = oid;
            }
            int startCnt = 0;

            try
            {
                startCnt = Environment.TickCount;

                result  = SNMP.Get(OID);
                exeTime = Environment.TickCount - startCnt;
            }
            catch (SnmpException ex)
            {
                SetLextmError(ex);
            }
            catch (Exception ex)
            {
                GetLastError = "ERROR: " + ex.JoinAllErrorMessages();
            }
            finally
            {
                result = ProcessFinally(ref exeTime, result, startCnt);
            }
            return(result);
        }
        // retourne le status du switch
        static public string getStatusSwitch(string ipAdress)
        {
            SNMP   snmp;
            int    DeviceId = 1;
            int    retries = 1;
            int    TimeoutInMS = 20000;
            string Result1Str; string status = "";

            try
            {
                string[] ErrorMessageText = new string[8];
                ErrorMessageText[0] = "service recquis";
                ErrorMessageText[1] = "Eteinte";
                ErrorMessageText[2] = "Bourrage papier";
                ErrorMessageText[3] = "porte ouverte";
                ErrorMessageText[4] = "pas de toner";
                ErrorMessageText[5] = "niveau toner bas";
                ErrorMessageText[6] = "plus de papier";
                ErrorMessageText[7] = "niveau de papier bas";

                snmp = new SNMP();
                snmp.Open(ipAdress, "public", retries, TimeoutInMS);//.1.3.6.1.2.1.2.2.1.7.25
                uint nbPort = snmp.GetAsByte(String.Format(".1.3.6.1.2.1.2.1.0"));
                snmp.Close();
                System.Console.WriteLine("nombre de port : " + nbPort);

                for (int i = 1; i <= nbPort; i++)
                {
                    snmp = new SNMP();
                    snmp.Open(ipAdress, "public", retries, TimeoutInMS);//.1.3.6.1.2.1.2.2.1.7.25//.1.3.6.1.2.1.2.1.0//.1.3.6.1.2.1.2.2.1.6.
                    string adressResult = snmp.Get(".1.3.6.1.2.1.2.2.1.6." + i);
                    byte[] ba           = Encoding.Default.GetBytes(adressResult);
                    string hexString    = BitConverter.ToString(ba);
                    uint   statusResult = snmp.GetAsByte(".1.3.6.1.2.1.2.2.1.8." + i);

                    switch (statusResult)
                    {
                    case 1:
                        Result1Str = "up";
                        break;

                    case 2:
                        Result1Str = "down";
                        break;

                    case 3:
                        Result1Str = "testing";
                        break;

                    case 4:
                        Result1Str = "unknown";
                        break;

                    case 5:
                        Result1Str = "dormant";
                        break;

                    case 6:
                        Result1Str = "notPresent";
                        break;

                    case 7:
                        Result1Str = "lowerLayerDown";
                        break;

                    default:
                        Result1Str = "code inconnu" + statusResult;
                        break;
                    }
                    Console.WriteLine("  port " + i + " adresse : " + hexString + " " + statusResult + " " + Result1Str);
                    snmp.Close();
                }
            }
            catch (Exception)
            {
                status = "Informations non disponibles...";
            }
            return(status);
        }
        //retourne le pourcentage d'encre présente dans x toner
        static public string getTonerStatus(string ipAdress, string printerName, int tonerNumber)
        {
            int    retries         = 1;
            int    TimeoutInMS     = 20000;
            int    tonerNumberDell = 0;
            string status;
            uint   currentlevel;
            uint   maxlevel;

            try
            {
                SNMP snmp = new SNMP();
                snmp.Open(ipAdress, "public", retries, TimeoutInMS);
                switch (tonerNumber)
                {
                case 1:
                    tonerNumberDell = 4;
                    break;

                case 2:
                    tonerNumberDell = 3;
                    break;

                case 3:
                    tonerNumberDell = 1;
                    break;

                case 4:
                    tonerNumberDell = 2;
                    break;
                }
                switch (printerName)
                {
                case "Dell 3010 cn":
                    currentlevel =
                        Convert.ToUInt32(snmp.Get(".1.3.6.1.2.1.43.11.1.1.9.1." +
                                                  tonerNumberDell.ToString()));
                    maxlevel =
                        Convert.ToUInt32(snmp.Get(".1.3.6.1.2.1.43.11.1.1.8.1." +
                                                  tonerNumberDell.ToString()));
                    break;

                default:
                    currentlevel =
                        Convert.ToUInt32(snmp.Get(".1.3.6.1.2.1.43.11.1.1.9.1." +
                                                  tonerNumber.ToString()));
                    maxlevel =
                        Convert.ToUInt32(snmp.Get(".1.3.6.1.2.1.43.11.1.1.8.1." +
                                                  tonerNumber.ToString()));
                    break;
                }
                uint remaininglevel = (currentlevel * 100 / maxlevel);
                status = remaininglevel.ToString();
                snmp.Close();
            }
            catch (Exception)
            {
                status = "Informations non disponibles...";
            }
            return(status);
        }