Added support for all Net.Interface.* parameters to Solaris subagent
authorVictor Kirhenshtein <victor@netxms.org>
Mon, 21 Feb 2005 16:42:48 +0000 (16:42 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Mon, 21 Feb 2005 16:42:48 +0000 (16:42 +0000)
ChangeLog
src/agent/subagents/sunos/main.cpp
src/agent/subagents/sunos/net.cpp

index fe0c683..4da3fa2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -18,6 +18,7 @@
 - Added interface for SMS drivers
 - Optimized access to collected DCI data in database
 - Added support for System.CPU.LoadAvg to Solaris subagent
+- Added support for all Net.Interface.* parameters to Solaris subagent
 
 
 *
index ff533e8..f2c84cd 100644 (file)
@@ -31,6 +31,9 @@ LONG H_DiskInfo(char *pszParam, char *pArg, char *pValue);
 LONG H_Hostname(char *pszParam, char *pArg, char *pValue);
 LONG H_LoadAvg(char *pszParam, char *pArg, char *pValue);
 LONG H_NetIfList(char *pszParam, char *pArg, NETXMS_VALUES_LIST *pValue);
+LONG H_NetIfAdminStatus(char *pszParam, char *pArg, char *pValue);
+LONG H_NetIfDescription(char *pszParam, char *pArg, char *pValue);
+LONG H_NetInterfaceStats(char *pszParam, char *pArg, char *pValue);
 LONG H_ProcessCount(char *pszParam, char *pArg, char *pValue);
 LONG H_ProcessInfo(char *pszParam, char *pArg, char *pValue);
 LONG H_ProcessList(char *pszParam, char *pArg, NETXMS_VALUES_LIST *pValue);
@@ -69,7 +72,17 @@ static NETXMS_SUBAGENT_PARAM m_parameters[] =
    { "Disk.Free(*)", H_DiskInfo, (char *)DISK_FREE, DCI_DT_UINT64, "Free disk space on *" },
    { "Disk.Total(*)", H_DiskInfo, (char *)DISK_TOTAL, DCI_DT_UINT64, "Total disk space on *" },
    { "Disk.Used(*)", H_DiskInfo, (char *)DISK_USED, DCI_DT_UINT64, "Used disk space on *" },
-   { "Process.Count(*)", H_ProcessCount, NULL, DCI_DT_UINT, "" },
+   { "Net.Interface.AdminStatus(*)", H_NetIfAdminStatus, NULL, DCI_DT_INT, "Administrative status of interface {instance}" },
+   { "Net.Interface.BytesIn(*)", H_NetInterfaceStats, "rbytes", DCI_DT_UINT, "Number of input bytes on interface {instance}" },
+   { "Net.Interface.BytesOut(*)", H_NetInterfaceStats, "obytes", DCI_DT_UINT, "Number of output bytes on interface {instance}" },
+   { "Net.Interface.Description(*)", H_NetIfDescription, NULL, DCI_DT_STRING, "" },
+   { "Net.Interface.InErrors(*)", H_NetInterfaceStats, "ierrors", DCI_DT_UINT, "Number of input errors on interface {instance}" },
+   { "Net.Interface.Link(*)", H_NetInterfaceStats, "link_up", DCI_DT_INT, "Link status for interface {instance}" },
+   { "Net.Interface.OutErrors(*)", H_NetInterfaceStats, "oerrors", DCI_DT_UINT, "Number of output errors on interface {instance}" },
+   { "Net.Interface.PacketsIn(*)", H_NetInterfaceStats, "ipackets", DCI_DT_UINT, "Number of input packets on interface {instance}" },
+   { "Net.Interface.PacketsOut(*)", H_NetInterfaceStats, "opackets", DCI_DT_UINT, "Number of output packets on interface {instance}" },
+   { "Net.Interface.Speed(*)", H_NetInterfaceStats, "ifspeed", DCI_DT_UINT, "Speed of interface {instance}" },
+   { "Process.Count(*)", H_ProcessCount, NULL, DCI_DT_UINT, "Number of proceses {instance}" },
    { "Process.KernelTime(*)", H_ProcessInfo, (char *)PROCINFO_KTIME, DCI_DT_UINT64, "" },
    { "Process.PageFaults(*)", H_ProcessInfo, (char *)PROCINFO_PF, DCI_DT_UINT64, "" },
    { "Process.UserTime(*)", H_ProcessInfo, (char *)PROCINFO_UTIME, DCI_DT_UINT64, "" },
index 5287d71..8ba40f6 100644 (file)
@@ -184,3 +184,178 @@ LONG H_NetIfList(char *pszParam, char *pArg, NETXMS_VALUES_LIST *pValue)
 
        return nRet;
 }
+
+
+//
+// Get interface description
+//
+
+LONG H_NetIfDescription(char *pszParam, char *pArg, char *pValue)
+{
+       char *eptr, szIfName[IF_NAMESIZE];
+       int nIndex, nFd;
+       struct lifreq rq;
+   LONG nRet = SYSINFO_RC_ERROR;
+
+   NxGetParameterArg(pszParam, 1, szIfName, IF_NAMESIZE);
+   if (szIfName[0] == 0)
+   {
+      nRet = SYSINFO_RC_UNSUPPORTED;
+   }
+   else
+   {
+      // Determine if parameter is index or name
+      nIndex = strtol(szIfName, &eptr, 10);
+      if (*eptr == 0)
+      {
+         // It's an index, determine name
+                       if (if_indextoname(nIndex, szIfName) == NULL)
+               nRet = SYSINFO_RC_UNSUPPORTED;
+      }
+       }
+
+       if (nRet != SYSINFO_RC_UNSUPPORTED)
+       {
+               ret_string(pValue, szIfName);
+               nRet = SYSINFO_RC_SUCCESS;
+       }
+
+       return nRet;
+}
+
+
+//
+// Get interface administrative status
+//
+
+LONG H_NetIfAdminStatus(char *pszParam, char *pArg, char *pValue)
+{
+       char *eptr, szIfName[IF_NAMESIZE];
+       int nIndex, nFd;
+       struct lifreq rq;
+   LONG nRet = SYSINFO_RC_ERROR;
+
+   NxGetParameterArg(pszParam, 1, szIfName, IF_NAMESIZE);
+   if (szIfName[0] == 0)
+   {
+      nRet = SYSINFO_RC_UNSUPPORTED;
+   }
+   else
+   {
+      // Determine if parameter is index or name
+      nIndex = strtol(szIfName, &eptr, 10);
+      if (*eptr == 0)
+      {
+         // It's an index, determine name
+                       if (if_indextoname(nIndex, szIfName) == NULL)
+               nRet = SYSINFO_RC_UNSUPPORTED;
+      }
+       }
+
+       if (nRet != SYSINFO_RC_UNSUPPORTED)
+       {
+               nFd = socket(AF_INET, SOCK_DGRAM, 0);
+               if (nFd >= 0)
+               {                         
+                       strcpy(rq.lifr_name, szIfName);
+                       if (ioctl(nFd, SIOCGLIFFLAGS, &rq) == 0)
+                       {
+                               ret_int(pValue, (rq.lifr_flags & IFF_UP) ? 1 : 0);
+                               nRet = SYSINFO_RC_SUCCESS;
+                       }
+                       close(nFd);                               
+               }
+       }
+
+       return nRet;
+}
+
+
+//
+// Get interface statistics
+//
+
+LONG H_NetInterfaceStats(char *pszParam, char *pArg, char *pValue)
+{
+   kstat_ctl_t *kc;
+   kstat_t *kp;
+   kstat_named_t *kn;
+       char *ptr, *eptr, szIfName[IF_NAMESIZE], szDevice[IF_NAMESIZE];
+       int nInstance, nIndex;
+   LONG nRet = SYSINFO_RC_ERROR;
+
+   NxGetParameterArg(pszParam, 1, szIfName, IF_NAMESIZE);
+   if (szIfName[0] == 0)
+   {
+      nRet = SYSINFO_RC_UNSUPPORTED;
+   }
+   else
+   {
+      // Determine if parameter is index or name
+      nIndex = strtol(szIfName, &eptr, 10);
+      if (*eptr == 0)
+      {
+         // It's an index, determine name
+                       if (if_indextoname(nIndex, szIfName) == NULL)
+               nRet = SYSINFO_RC_UNSUPPORTED;
+      }
+       }
+
+       if (nRet != SYSINFO_RC_UNSUPPORTED)
+       {
+               // Parse interface name and create device name and instance number
+               for(ptr = szIfName; (*ptr != 0) && (!isdigit(*ptr)); ptr++);
+               memcpy(szDevice, szIfName, ptr - szIfName);
+               szDevice[(int)(ptr - szIfName)] = 0;
+               for(eptr = ptr; (*eptr != 0) && isdigit(*eptr); eptr++);
+               *eptr = 0;
+               nInstance = atoi(ptr);
+
+       // Open kstat
+       kc = kstat_open();
+       if (kc != NULL)
+       {
+       kp = kstat_lookup(kc, szDevice, nInstance, szIfName);
+       if (kp != NULL)
+       {
+               if(kstat_read(kc, kp, 0) != -1)
+               {
+                                       kn = (kstat_named_t *)kstat_data_lookup(kp, pArg);
+                                       if (kn != NULL)
+                                       {
+                                               switch(kn->data_type)
+                                               {
+                                                       case KSTAT_DATA_CHAR:
+                                                               ret_string(pValue, kn->value.c);
+                                                               break;
+                                                       case KSTAT_DATA_INT32:
+                                                               ret_int(pValue, kn->value.i32);
+                                                               break;
+                                                       case KSTAT_DATA_UINT32:
+                                                               ret_uint(pValue, kn->value.ui32);
+                                                               break;
+                                                       case KSTAT_DATA_INT64:
+                                                               ret_int64(pValue, kn->value.i64);
+                                                               break;
+                                                       case KSTAT_DATA_UINT64:
+                                                               ret_uint64(pValue, kn->value.ui64);
+                                                               break;
+                                                       case KSTAT_DATA_FLOAT:
+                                                               ret_double(pValue, kn->value.f);
+                                                               break;
+                                                       case KSTAT_DATA_DOUBLE:
+                                                               ret_double(pValue, kn->value.d);
+                                                               break;
+                                                       default:
+                                                               ret_int(pValue, 0);
+                                               }
+                                               nRet = SYSINFO_RC_SUCCESS;
+                                       }
+               }
+       }
+       kstat_close(kc);
+       }
+       }
+
+   return nRet;
+}