Wrong Alert?

  • Hello

    I have created a job which send me an alert when D drive(dedicated drive for tempdb) free space is less than 2048 MB.

    When I executed,exec xp_fixeddrives it shows that D drive has 57000MB(`57 GB out of 60GB) free space, but we are continuously getting alert from job. Can someone please suggest?

    Job code :

    declare @Free_MB int

    create table #Free(
     Drive char(1),
     Free_MB int)

    insert into #Free exec xp_fixeddrives

    select @Free_MB = Free_MB from #Free where Drive = 'D'

    if @Free_MB < 2048
      exec msdb.dbo.sp_send_dbmail
       @recipients =  'mailid.com' ,
       @subject ='Space is critical on D Drive',
       @body = 'Less than 2 GB available'

  • If you run the following, what do you get?
    DECLARE @Free_MB int;

    CREATE TABLE #Free
      (Drive char(1),
      Free_MB int);

    INSERT INTO #Free EXEC xp_fixeddrives;

    SELECT Free_MB FROM #Free WHERE Drive = 'D';

    DROP TABLE #Free;
    GO

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • if that is a direct copy of your code, one thought could be that you haven't explicitly declared the end of your statements, this can always cause odd results?
    I've run your code with correct syntax and it seems to be ok? what results are you getting from the xp and from your temp table?
    One final thought, have you configured your job correctly? i.e. is the alert you are getting from the code or could you have "On success action: Quit the job reporting failure" configured? (I'm presuming you have alerts configured for failing jobs?)
    what is the alert you are getting from the job?

  • Sreejith! - Tuesday, June 6, 2017 6:23 AM

     but we are continuously getting alert from job. Can someone please suggest?

    Well, yes, you would.  You'll get it every time the job runs and finds that disk space is low.  How often does the job run?  You'll need to make it a little more sophisticated. Create a permanent database table with an AlertSent column.  When an alert is triggered and sent, update AlertSent to Yes.  If the job runs again and finds low space but AlertSent is Yes, don't send the alert.  If the job subsequently runs and doesn't find low space, reset AlertSent to No.

    John

  • Hi Thom
    Thanks for replying
    I have executed the code & it returned 57000MB.For some reason the query execution is entering into IF condition

    Hi Dim,

    Yes, There is no syntax error & job is configured correctly.

  • John Mitchell-245523 - Tuesday, June 6, 2017 6:56 AM

    Sreejith! - Tuesday, June 6, 2017 6:23 AM

     but we are continuously getting alert from job. Can someone please suggest?

    Well, yes, you would.  You'll get it every time the job runs and finds that disk space is low.  How often does the job run?  You'll need to make it a little more sophisticated. Create a permanent database table with an AlertSent column.  When an alert is triggered and sent, update AlertSent to Yes.  If the job runs again and finds low space but AlertSent is Yes, don't send the alert.  If the job subsequently runs and doesn't find low space, reset AlertSent to No.

    John

    Email is triggered even we have enough disk space. It is supposed to trigger email when we have low disk space(less than 2GB). Job is scheduled to run every one hour

  • As a thought, I'm wondering if the SQL Agent is running into a permission problem (either unable to run xp_fixeddrives, or being denied access to the drives themselves)

    Try modifying your job to store the results in a permanent table, let it run once, then see what's in the table.  If it's empty, there's your problem.  Then it becomes a case of tracking down where the permissions failure lies.

  • jasona.work - Tuesday, June 6, 2017 7:22 AM

    As a thought, I'm wondering if the SQL Agent is running into a permission problem (either unable to run xp_fixeddrives, or being denied access to the drives themselves)

    Try modifying your job to store the results in a permanent table, let it run once, then see what's in the table.  If it's empty, there's your problem.  Then it becomes a case of tracking down where the permissions failure lies.

    Service account has syadmin access on SQL Server

  • Sreejith! - Tuesday, June 6, 2017 7:31 AM

    jasona.work - Tuesday, June 6, 2017 7:22 AM

    As a thought, I'm wondering if the SQL Agent is running into a permission problem (either unable to run xp_fixeddrives, or being denied access to the drives themselves)

    Try modifying your job to store the results in a permanent table, let it run once, then see what's in the table.  If it's empty, there's your problem.  Then it becomes a case of tracking down where the permissions failure lies.

    Service account has syadmin access on SQL Server

    I'd still suggest letting it run once saving to a table you can query afterwards.  Verify that it's actually getting data to check against (after all, if for some reason when run as a job it's saving NULL for the drive free space, your alert will fire every single time.)

  • jasona.work - Tuesday, June 6, 2017 7:49 AM

    Sreejith! - Tuesday, June 6, 2017 7:31 AM

    jasona.work - Tuesday, June 6, 2017 7:22 AM

    As a thought, I'm wondering if the SQL Agent is running into a permission problem (either unable to run xp_fixeddrives, or being denied access to the drives themselves)

    Try modifying your job to store the results in a permanent table, let it run once, then see what's in the table.  If it's empty, there's your problem.  Then it becomes a case of tracking down where the permissions failure lies.

    Service account has syadmin access on SQL Server

    I'd still suggest letting it run once saving to a table you can query afterwards.  Verify that it's actually getting data to check against (after all, if for some reason when run as a job it's saving NULL for the drive free space, your alert will fire every single time.)

    Yes, and just because it's sysadmin, that doesn't automatically give it access to resources outside of SQL Server, such as the disk drives.

    John

  • jasona.work - Tuesday, June 6, 2017 7:49 AM

    Sreejith! - Tuesday, June 6, 2017 7:31 AM

    jasona.work - Tuesday, June 6, 2017 7:22 AM

    As a thought, I'm wondering if the SQL Agent is running into a permission problem (either unable to run xp_fixeddrives, or being denied access to the drives themselves)

    Try modifying your job to store the results in a permanent table, let it run once, then see what's in the table.  If it's empty, there's your problem.  Then it becomes a case of tracking down where the permissions failure lies.

    Service account has syadmin access on SQL Server

    I'd still suggest letting it run once saving to a table you can query afterwards.  Verify that it's actually getting data to check against (after all, if for some reason when run as a job it's saving NULL for the drive free space, your alert will fire every single time.)

    Hmmm...I might be missing your actual intention, but if the variable IS NULL, the code in the IF block will NOT execute.

    NULL < 2048 does not evaluate to TRUE.

    The action point is still very worthwhile, of course (seeing what values are being returned), but I just wanted to clarify this bit.

    Cheers!

  • jasona.work - Tuesday, June 6, 2017 7:49 AM

    I'd still suggest letting it run once saving to a table you can query afterwards.  Verify that it's actually getting data to check against (after all, if for some reason when run as a job it's saving NULL for the drive free space, your alert will fire every single time.)

    Curious, unless I'm missing something blindingly obvious (?) why would null fire the alert every time?
    If null < 2048 would result in false and so shouldn't fire the command? worst case scenario a null exception should be thrown and the procedure fail?

  • Jacob Wilkins - Tuesday, June 6, 2017 8:33 AM

    Hmmm...I might be missing your actual intention, but if the variable IS NULL, the code in the IF block will NOT execute.

    NULL < 2048 does not evaluate to TRUE.

    The action point is still very worthwhile, of course (seeing what values are being returned), but I just wanted to clarify this bit.

    Cheers!

    DimPerson - Tuesday, June 6, 2017 8:55 AM

    Curious, unless I'm missing something blindingly obvious (?) why would null fire the alert every time?
    If null < 2048 would result in false and so shouldn't fire the command? worst case scenario a null exception should be thrown and the procedure fail?

    You are both correct, I was wrong.  If it's reporting NULL it should just bail out and do nothing.

  • DimPerson - Tuesday, June 6, 2017 8:55 AM

    jasona.work - Tuesday, June 6, 2017 7:49 AM

    I'd still suggest letting it run once saving to a table you can query afterwards.  Verify that it's actually getting data to check against (after all, if for some reason when run as a job it's saving NULL for the drive free space, your alert will fire every single time.)

    Curious, unless I'm missing something blindingly obvious (?) why would null fire the alert every time?
    If null < 2048 would result in false and so shouldn't fire the command? worst case scenario a null exception should be thrown and the procedure fail?

    I apologize in advance for being pedantic, but strictly speaking NULL < 2048 should  evaluate to UNKNOWN. :rolleyes:

  • I tried to save it to table & alert got triggered again. As I mentioned earlier, D drive is a dedicated drive for TEMPDB and in SSMS available free space is showing as negative values; which is due to issue mentioned in below blog post
    https://blogs.msdn.microsoft.com/ialonso/2012/10/08/inaccurate-values-for-currently-allocated-space-and-available-free-space-in-the-shrink-file-dialog-for-tempdb-only/

    Does it has something to do with xp_fixeddrives procedure???

Viewing 15 posts - 1 through 15 (of 15 total)

You must be logged in to reply to this topic. Login to reply