NetXMS Support Forum

Please login or register.

Login with username, password and session length

Author Topic: Script for synology NAS  (Read 494 times)

CrUser

  • Newbie
  • *
  • Posts: 20
    • View Profile
Script for synology NAS
« on: December 12, 2018, 04:22:21 pm »

Hi,

I have one problem with scripting for maintenance of synology NAS equipment. unfortunately, Synology NAS server hasn't implement SNMP agent with sending traps for some alert. Because that I have to create events and alarm internaly from DCI parameters.
For the example, for the RAID status I can read DCI paratameter from NAS device which can be number of 1- 10. Every number present special condition of current RAID status. I have written one script to anaylize DCI parameters and generate specific event for any condition (number)
This is my script for DCI parameter named "raidStatus".

raid_Status= GetDCIValueByName($node, "raidStatus");
details = "NORMAL";
switch (raid_Status)
{
   case 1:
      evt = "SYNOLOGY_RAID_STATUS_NOTIFICATION";
      details = "NORMAL";
      break;
   case 2:
      evt = "SYNOLOGY_RAID_STATUS_NOTIFICATION";
      details = "REPAIRING";
      break;
   case 3:
      evt = "SYNOLOGY_RAID_STATUS_NOTIFICATION";
      details = "MIGRATING";
      break;
   case 4:
      evt = "SYNOLOGY_RAID_STATUS_NOTIFICATION";
      details = "EXPANDING";
      break;
    case 5:
      evt = "SYNOLOGY_RAID_STATUS_NOTIFICATION";
      details = "DELETING";
      break;
    case 6:
      evt = "SYNOLOGY_RAID_STATUS_NOTIFICATION";
      details = "CREATING";
      break;
    case 7:
      evt = "SYNOLOGY_RAID_STATUS_NOTIFICATION";
      details = "SYNCING";
      break;
    case 8:
      evt = "SYNOLOGY_RAID_STATUS_NOTIFICATION";
      details = "CHECKING";
      break;
    case 9:
      evt = "SYNOLOGY_RAID_STATUS_NOTIFICATION";
      details = "ASSEMBLING";
      break;
    case 10:
      evt = "SYNOLOGY_RAID_STATUS_NOTIFICATION";
      details = "CANCELING";
      break;
    case 11:
      evt = "SYNOLOGY_RAID_STATUS_ERROR";
      details = "DEGRADE";
      break;
    case 12:
      evt = "SYNOLOGY_RAID_STATUS_ERROR";
      details = "CRASHED";
      break;

PostEvent($node,evt,null, details);

Also, I have one event and suitable event procesing policy role with activation one NXSL script for creation new events for any RAID status case, like a "SYNOLOGY_RAID_STATUS_NOTIFICATION" with massage which I would get from my script, for example  "CHECKING".
Suitable Event for this case is configured with name "SYNOLOGY_RAID_STATUS_NOTIFICATION" and message
"Synology RAID status: %1"

During testing process I got NetXMS system error message that one of parameters can not convert to string.
I didn't found much guides for NXSL programing and I can't understand where is the problem with script posting parameters.

if anybody have suggestion for resolve this problem, please help me to solve this.

Thanks,
best regards,
Tomislav
Logged

gdodd

  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: Script for synology NAS
« Reply #1 on: December 13, 2018, 12:01:48 am »

My guess is that raid_Status is NULL or some other value that does not match any of the cases.

To catch this, add
Code: [Select]
    default:
      evt = "SYNOLOGY_RAID_STATUS_ERROR";
      details = "NO_STATUS";

Assuming that allows the script to run, check that "raidStatus" is the Parameter and not the Description for the DCI you are getting the value from.
Possibly the script is not being run on the node where the "raidStatus" DCI is located.
Logged

Tursiops

  • Sr. Member
  • ****
  • Posts: 400
    • View Profile
Re: Script for synology NAS
« Reply #2 on: December 19, 2018, 10:48:39 pm »

This is not directly related, but if I understand your requirements correctly it may be simpler to use the DCI itself to generate the events, rather than running another script over it.
For example, add a transformation script to the DCI similar to this (that's taken from our matching Synology DCI):
Code: [Select]
switch ( $1 )
{
case "1": return "Healthy";
case "2": return "Repairing";
case "3": return "Migrating";
case "4": return "Expanding";
case "5": return "Deleting";
case "6": return "Creating";
case "7": return "Syncing";
case "8": return "Parity Checking";
case "9": return "Assembling";
case "10": return "Cancelling";
case "11": return "Degraded";
case "12": return "Crashed";
default: return "INVALID DATA (". $1 .")";
}
Then use Thresholds to trigger events based on the above. The data collected is passed on to the event.
You could also configure the thresholds to then automatically close any alerts (i.e. trigger a "normal/reset" style event and configure it to close matching alarms in the event processing policy) if the threshold goes back to normal.
All within the DCI without the need for calling an external script to read the DCI value.
Logged

CrUser

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Script for synology NAS
« Reply #3 on: January 03, 2019, 11:59:59 am »

Thank guys for this advice, I will try both and I hope that it will be solved.
Logged

CrUser

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Script for synology NAS
« Reply #4 on: January 03, 2019, 04:02:50 pm »

Hi,

I have resolved this script error. I found mistake on first line "raid_Status= GetDCIValueByName($node, "raidStatus");"
DCI parameter must be configured by DCI ID "raid_Status= GetDCIValueByName($node, "1.3.6.1.4.1.6574.3.1.1.3.0");
Now everything is working fine.
First I am put suggested code to eliminate error for null value of DCI parameter and after that I went to read again function GetDCIValueByName and found my mistake of parameters description.

Also, I will try the second suggestion to put script directly in Threshold of DCI value but I have only one solution resolved.

Thanks guys,

Have a nice day and happy new year 2019.
Tomislav

Logged