Forum Discussion

Marquez's avatar
Marquez
Level 3
10 years ago

Can a Linux NetBackup Appliance Media Server write to Windows Event Log?

My current monitoring software scrapes the windows Event Viewer, problem is all netbackup jobs are recorded on a Linux Media Server. Is there a way to send stats of the backups from the Linux Serv...
  • sdo's avatar
    10 years ago

    If you have a Windows Media Server or Windows Admin Host, then you could try this:

    1) Start a DOS/CMD box, and enter:

    bpdbjobs -stay_alive -autorefresh -most_columns > a.txt

    2) cscript a.vbs

    ...to run the script in the text box below:

    Option Explicit
    ' Written by sdo, 26-Aug-2014.
    Dim go_fso, go_wsh, gs_fields
    Set go_fso = CreateObject( "Scripting.FileSystemObject" )
    Set go_wsh = CreateObject( "WScript.Shell" )
    Call s_main()
    WScript.Quit(0)
    
    Sub s_main()
      Dim ls_file, lo_file, ls_rec, ll_recs, ll_err, lb_sleep, ls_fields
      ls_file = "a.txt"
      Set lo_file = go_fso.OpenTextFile( ls_file )
      ll_recs = 0
      lb_sleep = False
      While True
        On Error Resume Next
          ls_rec = lo_file.ReadLine()
          ll_err = Err.Number
        On Error Goto 0
        Select Case ll_err
        Case 0
          ll_recs = ll_recs + 1
          lb_sleep = False
          Set ls_fields = Nothing
          gs_fields = Split( ls_rec, "," )
          WScript.Echo "rec: " & ll_recs & "  fields: " & UBound( gs_fields ) & "  " & ls_rec
          If UBound( gs_fields ) = 58 Then
            Call s_process()
          Else
            WScript.Echo "...ignoring fragmented record..."
          End If
        Case 62
          If Not lb_sleep Then WScript.Echo "...sleeping..."
          lb_sleep = True
          WScript.Sleep 10
        Case Else
          WScript.Echo "Error " & ll_err
          WScript.Quit( ll_err )
        End Select
      Wend
    End Sub
    
    Sub s_process()
      Dim ls_job_id, ls_job_type, ls_job_state, ls_job_status
      Dim ls_job_policy, ls_job_schedule, ls_job_client, ls_job_schedule_type
      Dim ls_log
      ls_job_id     = gs_fields( 0 )
      ls_job_type   = gs_fields( 1 )
      ls_job_state  = gs_fields( 2 )
      ls_job_status = gs_fields( 3 ) 
      Select Case ls_job_state
      Case "3" 'done
        Select Case ls_job_type
        Case "0", "6" '0=backup 6=catalog-backup
          Select Case ls_job_status
          Case "0", "1"
          Case Else
            ls_job_policy   = gs_fields( 4 )
            ls_job_schedule = gs_fields( 5 )
            ls_job_client   = gs_fields( 6 )
            ls_job_schedule_type = gs_fields( 22 )
            If ls_job_schedule = "-" Then
              Select Case ls_job_schedule_type
              Case "0" : ls_job_schedule = "(full)"
              Case "1" : ls_job_schedule = "(diff)"
              Case "2" : ls_job_schedule = "(user-backup)"
              Case "3" : ls_job_schedule = "(user-archive)"
              Case "4" : ls_job_schedule = "(cinc)"
              Case Else: ls_job_schedule = "(unknown)"
              End Select
            End If
            ls_log = "backup failed, job: " & ls_job_id
            ls_log = ls_log & ", status: " & ls_job_status
            ls_log = ls_log & ", client: " & ls_job_client
            ls_log = ls_log & ", policy: " & ls_job_policy
            ls_log = ls_log & ", schedule: " & ls_job_schedule
            WScript.Echo ls_log
            go_wsh.LogEvent "1", ls_log
          End Select
        End Select
      End Select
    End Sub

     

    I'm not sure how much more time I can put in to this, or whether it will be suitable in the long term, or whether it will work in the real world (but it did seem to run ok in my test area) - and it is unsupported, and uses undocumented features of bpdbjobs, so Symantec won't support you.

    I might be able to help further, but I think you'll have more fun tweaking the script for yourself.  :)

    One thing that could be done - is to keep a record of which jobs have already 'logged' to the event log, so that if you restart it then it doesn't splat the event log with multiple entries, and use better file names, keep the logs, or filter selected records in to a permanent record, or just better logging, - ah, so many ideas...

    And watch out for line wrap - it should be fairly obvious which lines are wrapped.

    HTH.